Last active
March 16, 2017 16:19
-
-
Save devNoiseConsulting/a4961a7dc7be2f23635547576336ff22 to your computer and use it in GitHub Desktop.
Alphabetical Word Check - PhillyDev Slack #daily_programmer - 20170302
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
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