Searching backwards

Report a typo

You have an array that stores the results of a dice roll:

const results = [3, 5, 2, 1, 2, 3, 4, 6, 1, 5];

In the code below an element is given to the search() function. Change it so that the function searches for the last occurrence of the element and returns its index.

Sample Input 1:

5

Sample Output 1:

9
Write a program in JavaScript
const results = [3, 5, 2, 1, 2, 3, 4, 6, 1, 5];

function search(element) {
// Write your code here
}
___

Create a free account to access the full topic