-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIsograms.js
More file actions
20 lines (16 loc) · 807 Bytes
/
Copy pathIsograms.js
File metadata and controls
20 lines (16 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// 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.
// isIsogram("Dermatoglyphics") == true
// isIsogram("aba") == false
// isIsogram("moOse") == false // -- ignore letter case
function isIsogram(str) {
str = str.toLowerCase().split('')
while (str.length > 0) {
if (str.indexOf(str.pop()) != -1) 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)