-
Notifications
You must be signed in to change notification settings - Fork 1
/
Isograms.js
33 lines (29 loc) · 1.09 KB
/
Isograms.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
// 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)
//P: string
//R: return true and false
//E:
//P:
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;
}
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" )
// isIsogram("Dermatoglyphics")
// isIsogram("aba")