JSFiddle - React, Tailwind, and code Playground
by Jessie Lau
JavaScript
var lengthOfSequence = function (arr, n) {
// TODO: Write some scripts here
var counter = 1;
var numN = 0;
for (var i = arr.indexOf(n) + 1; i <= arr.length; i++) {
if (arr[i] == n) {
numN++;
}
}
if (numN < 2 || numN > 2) {
return 0;
}
};
//console.log(lengthOfSequence([-7, 6, 2, -7, 4], -7));
//console.log(lengthOfSequence([-7, 5, 0, 2, 9, 5], 5));
console.log(lengthOfSequence([-7, 5, 0, 5, 2, 9, 5], 5));