Array.prototype.findLastIndexadvancedconst logs = ['ok', 'error', 'ok', 'error']
logs.findLastIndex(l => l === 'error') // β 3Use findLastIndex() when you need the index of the most recent occurrence of a condition.
findLastIndex() can be used to find the last element that meets a condition requiring knowledge of the whole array β like being a duplicate.
Challenge: Implement lastDuplicateIndex(arr) that returns the index of the last element that appears more than once.
lastDuplicateIndex([1, 2, 3, 2, 1]) // β 4 (1 appears at 0 and 4)
lastDuplicateIndex([1, 2, 3]) // β -1