Hi.
Inside the function you should use the “arr” argument, not the “testArr” array.
When you call
console.log(nextInLine([5,6,7,8,9], 1));
your function use the “testArr” array not the “[5,6,7,8,9]” array.
Every time when you call the function , it use the “testArr” array and not the submitted array.
Don’t need make the “remove” variable. Instead it use the “item”. Give them a new value. It is not bad , just not necessary.
You are not using the array passed as an argument to the function in function nextInLine(arr, item)
Your function would only work if there were an array named testArr and could not be used with any other arrays
let testArr = ['b','d','a','c','f','e'];
function sort1(arr){
testArr.sort();
return testArr.pop();
}
console.log(sort1(testArr)); //f
console.log(sort1(['z','z','z'])); // 'e' not 'z'
Written like this the function will take any array passed to it as an argument.
let testArr = ['b','d','a','c','f','e'];
function sort2(arr){
arr.sort();
return arr.pop();
}
console.log(sort2(testArr)); // f
console.log(sort2(['z','z','z'])); // z