-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanagramDirection.js
More file actions
38 lines (32 loc) · 1.09 KB
/
anagramDirection.js
File metadata and controls
38 lines (32 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Kata: Anagram Detection?
// Difficulty: 7kyu
// Link: https://www.codewars.com/kata/529eef7a9194e0cbc1000255/train/javascript
/*
Description:
An anagram is the result of rearranging the letters of a word to produce a new word.
Return true if the two arguments given are anagrams of each other.
Examples:
"foefet" is an anagram of "toffee"
"Buckethead" is an anagram of "DeathCubeK"
*/
// Solution (on):
var isAnagram = function(test, original) {
return test.toLowerCase().split('').sort().join('') ===
original.toLowerCase().split('').sort().join('');
};
// Alternative solution (off):
/*
var isAnagram = function(test, original) {
const sortedTest = test.toLowerCase().split('').sort().join('');
const sortedOriginal = original.toLowerCase().split('').sort().join('');
return sortedTest === sortedOriginal;
};
*/
/*
Test cases:
console.log(isAnagram("foefet", "toffee")); // true
console.log(isAnagram("Buckethead", "DeathCubeK")); // true
console.log(isAnagram("Twoo", "WooT")); // true
console.log(isAnagram("dumble", "bumble")); // false
console.log(isAnagram("ound", "round")); // false
*/