-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpermutations.js
More file actions
38 lines (29 loc) · 777 Bytes
/
permutations.js
File metadata and controls
38 lines (29 loc) · 777 Bytes
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
// Check Permutation: Given two strings, write a method to decide if one is a
// permutation of the other.
function isPermutation(first, second) {
const firstSorted = first
.split("")
.sort()
.join("")
.toLowerCase();
const secondSorted = second
.split("")
.sort()
.join("")
.toLowerCase();
return firstSorted == secondSorted;
}
console.log(isPermutation("hot", "toh"));
console.log(isPermutation("applee", "apple"));
function ifPermutation(first, second) {
letterMap = new Map();
for (let letter in first) {
if (letterMap.has(letter)) {
letterMap.set(letter, letterMap.get(letter));
} else {
letterMap.set(letter, 1);
}
}
const mismatchLetters = false;
letterMap.forEach((value, key) => )
}