10-24-2020 10:51 PM
I need to find arrays where all values are equal. What’s the fastest way to do this? Should I loop through it and just compare values?
['a', 'a', 'a', 'a'] // true
['a', 'a', 'b', 'a'] // false
Solved! Go to Solution.
10-25-2020 06:51 AM
The Array.reduce function appears to be effective for this:
shortened syntax:
$myArray.reduce((av,cv,ci,ar) => (av && (ar[0] == cv)), true)
or verbose syntax:
$myArray.reduce((accumulatedValue,currentValue,currentIndex,originalArray) => (accumulatedValue && (originalArray[0] == currentValue)), true)
10-25-2020 06:51 AM
The Array.reduce function appears to be effective for this:
shortened syntax:
$myArray.reduce((av,cv,ci,ar) => (av && (ar[0] == cv)), true)
or verbose syntax:
$myArray.reduce((accumulatedValue,currentValue,currentIndex,originalArray) => (accumulatedValue && (originalArray[0] == currentValue)), true)
10-25-2020 11:43 AM
Thank you. this worked!!