Skip to content

Instantly share code, notes, and snippets.

@devNoiseConsulting
Last active March 16, 2017 16:19
Show Gist options
  • Save devNoiseConsulting/a4961a7dc7be2f23635547576336ff22 to your computer and use it in GitHub Desktop.
Save devNoiseConsulting/a4961a7dc7be2f23635547576336ff22 to your computer and use it in GitHub Desktop.
Alphabetical Word Check - PhillyDev Slack #daily_programmer - 20170302
let words = [
'abort', 'times', 'alloy', 'taught', 'arrow', 'know', 'below', 'onscreen',
'berry', 'idea', 'cello', 'spoonfeed', 'asked', 'deist', 'worlds', 'feint',
'best', 'floss', 'suggest', 'hilly', 'hippy'
];
function alphabeticalWord(word) {
let letters = word.split('').sort().join('');
// return (word == letters) ? true : false;
// Simplifing the return statement after feedback from Brian McElaney
return (word == letters);
}
function alphabeticalWordReverse(word) {
let letters = word.split('').sort().reverse().join('');
return (word == letters);
}
console.log('\Check:');
let checks = words.map(alphabeticalWord);
checks.forEach(function(result, i) {
console.log(words[i], result);
});
console.log('\nReverse Check:');
checks = words.map(alphabeticalWordReverse);
checks.forEach(function(result, i) {
console.log(words[i], result);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment