Challenge
The task is simple. Given an array and a first and last value: Return the first of the last after the first, and the last of the first before the last.
Or simply: Given an array, var1, var2.
Example Array:
[ var2, , var1, , var2, , var2, var1, var2, ]
Return:
- The index of the first var2 on the right side of the first var1 that appears in the array.
[ var2, , first var1, , first var2, , second var2, var1, third var2, ]
- The index of the first var1 on the left side of the last var2 that appears in the array.
[ var2, , second var1, , var2, , var2, first var1,last var2, ]
Input
Two distinct positive integers
Array of positive integers
Output
Index of answers, in order
Rules
The array will contain at least one of each variable (minimum size of 2)
Assume inputs work
Example:
0, 1 [1, 0]
or similar would fail
Examples
Input
First = 2; Last = 4; [0, 2, 4, 2, 3, 1, 4, 0, 1, 2, 4, 9]
Output
2, 9
Input
First = 4; Last = 2; [0, 2, 4, 2, 3, 1, 4, 0, 1, 2, 4, 9]
Output
3, 6
Input
First = 0; Last = 1; [0, 1]
Output
1, 0
var1
be equal tovar2
? \$\endgroup\$9, 2
,6, 3
and0, 1
respectively (or plus one if the output is 1-indexed). \$\endgroup\$