9
I have the following code that works perfectly.
In it I possess a string and check whether all of its characters are equal or not:
var numbers = '1111121111',
firstNumber = numbers.substr(0,1),
numbersEquals = true;
for(let i = 1; i < numbers.length; i++) {
if (numbers[i] != firstNumber) numbersEquals = false;
}
console.log('numbersEquals = ' + numbersEquals)
There is an easier way or a ready method to do this?
I think I’m using too much code to do something simple.
@Lucas does not know this notation yet '[...new Set(Numbers)]'
– alan
@Lan now you know :)
– BrTkCa
@There are two things there, if you want to research: the
Set
, and the Operator spread...
.– bfavaretto
thanks @Lucascosta! :)
– alan
I’m giving a studied at this now @bfavaretto worth! ;)
– alan