findLastIndex

PHOTO EMBED

Fri Oct 23 2020 16:29:07 GMT+0000 (Coordinated Universal Time)

Saved by [deleted user] #javascript

const findLastIndex = (array, predicate) => {
    let l = array.length;
    while (l--) {
        if (predicate(array[l], l, array)) {
            return l;
        }
    }

    return -1;
};
content_copyCOPY

Find the last index of something in an array where a predicate (callback) is true. Based off a stack overflow answer.

https://stackoverflow.com/a/53187807