Last active
July 4, 2016 11:51
-
-
Save pranavghate94/afb157ad19386503ec0d79288e40bf87 to your computer and use it in GitHub Desktop.
Find the longest N consecutive string from the string array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Native Browser JavaScript | |
| >>> abigailtheta |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment