-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIsograms.js
More file actions
33 lines (23 loc) · 913 Bytes
/
Copy pathIsograms.js
File metadata and controls
33 lines (23 loc) · 913 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
// An isogram is a word that has no repeating letters, consecutive or non-consecutive. Implement a function that determines whether a string that contains only letters is an isogram. Assume the empty string is an isogram. Ignore letter case.
// Example: (Input --> Output)
// "Dermatoglyphics" --> true "aba" --> false "moOse" --> false (ignore letter case)
// isIsogram "Dermatoglyphics" = true
// isIsogram "moose" = false
// isIsogram "aba" = false
function isIsogram(str){
return !str || str.toLowerCase().split('').every((el, i, str) => str.indexOf(el) === i)
}
//different approach
function isIsogram(str){
return new Set(str.toUpperCase()).size == str.length;
}
//different approach
function isIsogram(str){
var i, j;
str = str.toLowerCase();
for(i = 0; i < str.length; ++i)
for(j = i + 1; j < str.length; ++j)
if(str[i] === str[j])
return false;
return true;
}