-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay61.js
More file actions
23 lines (20 loc) · 985 Bytes
/
Day61.js
File metadata and controls
23 lines (20 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//* Question:
//* Write a function isAnagram that takes in two strings and returns true if they are anagrams of each other,
//* and false otherwise. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase,
//* typically using all the original letters exactly once.
function isAnagram(s1, s2) {
// Helper function to sort the letters of a string
function sortString(str) {
return str.split('').sort().join('');
}
// Compare the sorted versions of the strings
return sortString(s1) === sortString(s2);
}
// Test cases
console.log(isAnagram("listen", "silent")); // true
console.log(isAnagram("hello", "world")); // false
console.log(isAnagram("evil", "vile")); // true
console.log(isAnagram("fluster", "restful")); // true
console.log(isAnagram("dormitory", "dirtyroom")); // true
console.log(isAnagram("conversation", "voicesranton")); // true
console.log(isAnagram("conversation", "voicesrando")); // false