Instructions:
An anagram is the result of rearranging the letters of a word to produce a new word (see wikipedia).
Note: anagrams are case insensitive
Complete the function to return true if the two arguments given are anagrams of each other; return false otherwise.
Examples
"foefet" is an anagram of "toffee"
"Buckethead" is an anagram of "DeathCubeK"
Solution:
var isAnagram = function(test, original) {
const ordered = str => str.toLowerCase().split('').sort().join();
return ordered(test) === ordered(original);
};
Thoughts:
- I created a function named ordered that takes a string and transforms it 1st to lower case, then will split to an array of letters and sort it alphabetically. At the ens it does join the string back together in the new order.
- I do compare through the function above the 1st string to the 2nd string and returned true or false.
Top comments (0)