What's wrong with my code?
function longestConsec(strarr, k) {
var currentLongest = "";
var counter = 0;
var outPut = [];
if(strarr.length === 0 || k > strarr.length || k <= 0){
return "";
}
for(var i = 0; i < strarr.length; i++){
if(strarr[i] > currentLongest){
currentLongest = strarr[i];
}
}
while(currentLongest !== strarr[counter]){
counter = counter + 1
}
for (var j = 0; j < k; j ++){
outPut = outPut.push(strarr[counter + j]);
}
outPut = outPut.join("");
return outPut;
}
See Question&Answers more detail:os