DEV Community

Discussion on: Introducing `findLast` and `findLastIndex`

Collapse
 
link2twenty profile image
Andrew Bone
const findLastIndex = (array, comparitor) => {
  for (let i = array.length - 1; i >= 0; i--)
    if (comparitor(array[i])) return i;

  return -1;
}

findLastIndex(arr, el => el.letter === 'c')
Enter fullscreen mode Exit fullscreen mode

It saves having to write a function to go through them for you. I generally think anytime the browser takes on some of complication I might have to face, that can only be a good thing.

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

I generally think anytime the browser takes on some of complication I might have to face, that can only be a good thing.

Well, yes, but only up to a certain point; if there was too much clutter, it'd get more and more difficult to find the right method for a task and in the end people would just end up writing their own methods anyway.

Also JS has a habit of cramming too much functionality into one feature, but harms the feature in the process, like is the case with map which completely messes up variadic functions because for some reason it passes along more arguments than it needs to.