Skip to content

Instantly share code, notes, and snippets.

@pranavghate94
Last active July 4, 2016 11:51
Show Gist options
  • Select an option

  • Save pranavghate94/afb157ad19386503ec0d79288e40bf87 to your computer and use it in GitHub Desktop.

Select an option

Save pranavghate94/afb157ad19386503ec0d79288e40bf87 to your computer and use it in GitHub Desktop.
Find the longest N consecutive string from the string array.
function longest(strarr,k){
var start = 0;
var end = k;
var superstring='';
while(end !== strarr.length+1){
var temp = strarr.slice(start,end).join('');
if(temp.length >= superstring.length){
superstring = temp;
}
start++;
end++;
}
return superstring;
}
var test = longest(["zone","abigail","theta","form","libe","zas"],2);
console.log(test);
Native Browser JavaScript
>>> abigailtheta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment