---------- Forwarded message ----------
From: Dmitry Shulgin <shulhind...@gmail.com>
Date: 2018-07-05 10:36 GMT+03:00
Subject: Feature proposal
To: es-discuss@mozilla.org


I came across a task of finding an index of the last element in array that
satisfies the condition, so i reversed array and found it by *findIndex *
function.
I was thinking:
Why do we have *findIndex*` method, but no *findLastIndex*?
It seems logical to follow *[index|lastIndex]Of* pair, doesn't it?
Reversing array in this case seems too complicated to me.

So, i would like to suggest new method like
*Array.prototype.findLastIndex()*

Example:

function isPrime(element, index, array) {
  var start = 2;
  while (start <= Math.sqrt(element)) {
    if (element % start++ < 1) {
      return false;
    }
  }
  return element > 1;
}

console.log([4, 6, 8, 12].findIndex(isPrime)); // -1, not found
console.log([7, 4, 6, 7, 12].findIndexLast(isPrime)); // 3


Would be glad to implement, if it makes sense.

Thx for replies.

P.S. Small issue on GitHub was closed due to offtop (not an issue, as i
understand).
https://github.com/tc39/ecma262/issues/1253
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to