I was comparing two branches and there is a divergence in code while the + operator
, in my opinion it doesn't make any difference since it's push.
Is there any difference?
Before
if (numberPattern.test(val)) {
var getNumbers = val.match(numberPattern);
for (i = 0; i < getNumbers.length; i++) {
valores.push(getNumbers[i])
}
}
After
if (numberPattern.test(val)) {
var getNumbers = val.match(numberPattern);
for (i = 0; i < getNumbers.length; i++) {
valores.push(+getNumbers[i])
}
}
The push() method changes the original array by adding an item to the end. When you add an item, you're mutating the original array.
The push() adds elements to the end of an array and returns the new length of the array. Thus your return here is invalid. The concat() method is used to merge arrays. Concat does not change the existing arrays, but instead returns a new array.
push() method is used to push one or more values into the array. This method changes the length of the array by the number of elements added to the array. Parameters This method contains as many numbers of parameters as the number of elements to be inserted into the array.
As you can see, spread is 50% faster for smaller arrays, while concat is multiple times faster on large arrays.
It is converting it to a Number
, where the other case is leaving it as as string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With