We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
findLastIndex
Array has finding functions, find() and findIndex(). find() returns the element, and findIndex() returns the index.
Array
find()
findIndex()
Now, we have findLast() in std/collections, this returns the element.
findLast()
So, how about add findLastIndex() ? It is almost same as findLast(), but returns the index of the last found element.
findLastIndex()
import { Predicate } from "./types.ts"; export function findLastIndex<T>( array: Array<T>, predicate: Predicate<T>, ): number { for (let i = array.length - 1; i >= 0; i -= 1) { const element = array[i]; if (predicate(element)) { return i; } } return -1; }
The text was updated successfully, but these errors were encountered:
Because we already have findLast in std/collections, this proposal makes sense to me.
This can be implemented in V8 in some future https://github.com/tc39/proposal-array-find-from-last https://chromium-review.googlesource.com/c/v8/v8/+/3037160 . If that happens, then let's deprecate it.
Sorry, something went wrong.
collections
Successfully merging a pull request may close this issue.
Array
has finding functions,find()
andfindIndex()
.find()
returns the element, andfindIndex()
returns the index.Now, we have
findLast()
in std/collections, this returns the element.So, how about add
findLastIndex()
?It is almost same as
findLast()
, but returns the index of the last found element.The text was updated successfully, but these errors were encountered: