Created
October 26, 2015 03:29
-
-
Save KevinTCoughlin/809cd1c6921c5c05e1ff to your computer and use it in GitHub Desktop.
This file contains 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
var input = [ | |
'billowy', | |
'biopsy', | |
'chinos', | |
'defaced', | |
'chintz', | |
'sponged', | |
'bijoux', | |
'abhors', | |
'fiddle', | |
'begins', | |
'chimps', | |
'wronged' | |
]; | |
function isInAlphabeticalOrder(input) { | |
var results = new Map(); | |
input.forEach(function(word) { | |
var result = word.split("").every(function(curr, idx, arr) { | |
if (idx < arr.length - 1 ) return curr < arr[idx + 1]; | |
else return true; | |
}); | |
results.set(word, result); | |
}); | |
return results; | |
} | |
function print(results) { | |
results.forEach(function(value, key) { | |
console.log(key, value ? '' : 'NOT', 'IN ORDER'); | |
}); | |
} | |
print(isInAlphabeticalOrder(input)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment