In PHP, a solution would be like this:
if ($telefone == str_repeat($n, 11) || $telefone == str_repeat($n, 12)){
return false;
}
Explanation
This test you have in the code is a little strange and ends up making it difficult to read, not giving clear idea of your intention.
What new Array(11).join(n) does is create an array of a certain size in which all houses have undefined, and joins everything with the last tab. But the undefineds that are in all houses are represented as empty text, soon will get a string where the separator has been repeated several times.
See the following example:
console.log(new Array(11).join('a'));
However, it would be better to use the repeat da String, which is much clearer in its intention:
console.log('a'.repeat(11));
Even if the value to repeat is not a string can always turn it into string and then apply the repeat:
let x = 3;
console.log(x.toString().repeat(11));
In php has the function str_repeat who does precisely the same:
echo str_repeat('a', 11); //aaaaaaaaaa
what is in the variable "n"?
– lpFranz
What is in the variable
nand the variable$telefoneis as string or array?– Mauro Alexandre
After the questions I saw that it would be better to complete the code
– Marcelo