-
Notifications
You must be signed in to change notification settings - Fork 0
/
kata.js
42 lines (30 loc) · 925 Bytes
/
kata.js
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
39
40
41
42
// #1
// function isIsogram(str) {
// let lowerArray = str.toLowerCase().split("");
// let x = Array.from(new Set(lowerArray));
// if (x.length === lowerArray.length || lowerArray.length === 0) {
// return true;
// } else {
// return false;
// }
// }
// #2
// function isIsogram(str) {
// return str.toLowerCase().split('').sort().join('') === Array.from(new Set(str.toLowerCase().split(''))).sort().join('')
// }
// #3
function isIsogram(str) {
return new Set(str.toUpperCase()).size == str.length;
}
console.log(isIsogram("Dermatoglyphics"));
// true
console.log(isIsogram("isogram"));
// true
console.log(isIsogram("aba"));
// false, "same chars may not be adjacent"
console.log(isIsogram("moOse"));
// false, "same chars may not be same case"
console.log(isIsogram("isIsogram"));
// false
console.log(isIsogram(""));
// true, "an empty string is a valid isogram"