Last active
June 28, 2017 17:08
-
-
Save nathanjwtx/81f922e916e2073fba88c74e25c31019 to your computer and use it in GitHub Desktop.
Find the common words in two strings and return an alphabetically sorted string of common words
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 commonWords (first, second) { | |
var a = first.split(',') | |
var b = second.split(',') | |
var c = [] | |
for (var i = 0; i < a.length; i++) { | |
for (var j = 0; j < b.length; j++) { | |
if (a[i] === b[j] && c.indexOf(a[i]) !== null) { | |
c.push(a[i]) | |
} | |
} | |
} | |
return c.sort().toString() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment