How to write that 1 sign of the number was not equal to 2 and 3 and 4 Example 1234 norms, 1214 are identical, 1231 are the same. Does not roll (rands [0]! = Rands [1] || rands [2] || rands [3])

function randomInteger(ar) { ddd="ΠΎΠ΄ΠΈΠ½Π°ΠΊΠΎΠ²Ρ‹Π΅"; rand = ar; rands=String(rand); if(rands[0] != rands[1] || rands[2] || rands[3] ){ return rands; }else return ddd; } console.log(randomInteger(1010)); 
  • compare with each and you will be happy. - teran
  • I know that this is a ride, but I thought it could be something like this - Starbax
  • it is possible to push an array, you can write a cycle, you can check it regularly. even as you can. but not as you have written. - teran
  • the number is only four digits? What result is expected at 1222 ? - Grundy

1 answer 1

 function check(str) { return str.lastIndexOf(str[0]) == 0 ? 'ΠžΠ΄ΠΈΠ½Π°ΠΊΠΎΠ²Ρ‹Π΅' : 'НСодинаковыС'; } console.log(check('1234')); console.log(check('1214')); 

  • about the length, by the way, not a word was said. 12341 here - teran
  • one
    @teran, no, there in the question to compare 1 - I understand the first character with all the others, but not general repetition - Grundy
  • @teran Judging by the code in question, 5-digit lines are not supposed there. But if you wish, you can add another check. str.substr(0, 4).lastIndexOf(... :) - Yaant
  • one
    @Grundy yes xs, in my opinion 2-3-4 is not all the others, but only 2,3 and 4th. - teran