Skip to content

Instantly share code, notes, and snippets.

@KevinTCoughlin
Created October 26, 2015 03:29
Show Gist options
  • Save KevinTCoughlin/809cd1c6921c5c05e1ff to your computer and use it in GitHub Desktop.
Save KevinTCoughlin/809cd1c6921c5c05e1ff to your computer and use it in GitHub Desktop.
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