sorry you get 1, and need again to subtract the array length, `arr.length
-1 - 1` to get the final result 3

Le mer. 18 juil. 2018 à 18:41, Cyril Auburtin <[email protected]> a
écrit :

> there you go
> ```
> console.log([7, 4, 6, 7, 12].findIndex((_, i, a) =>
> isPrime(a[a.length-1-i]))); // 3
> ```
>
> Le mer. 18 juil. 2018 à 11:17, Dmitry Shulgin <[email protected]> a
> écrit :
>
>>
>> ---------- Forwarded message ----------
>> From: Dmitry Shulgin <[email protected]>
>> Date: 2018-07-05 10:36 GMT+03:00
>> Subject: Feature proposal
>> To: [email protected]
>>
>>
>> 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
>> [email protected]
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to