String.prototype.lastIndexOfintermediateconst str = 'abcabc'
str.lastIndexOf('a') // β 3
str.lastIndexOf('z') // β -1
str.lastIndexOf('b', 3) // β 1Use lastIndexOf() to find the index of the last occurrence of a substring, searching from right to left.
The optional second argument fromIndex tells the search to start from that position and go backward.
Challenge: Implement lastBefore(str, sub, pos) using .lastIndexOf(sub, pos).
lastBefore('abcabc', 'a', 4) // β 3
lastBefore('abcabc', 'a', 2) // β 0