-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisograms.js
More file actions
16 lines (13 loc) · 844 Bytes
/
isograms.js
File metadata and controls
16 lines (13 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// 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)
function isIsogram(str){
if(isNaN(str)) {
let arr = str.toLowerCase().split(""); // create array to split chars
for(let i = 0; i < arr.length; i++) {
if(!isNaN(arr[i])) { return false; } // check if the array contains a number
}
if (new Set([...arr]).size == arr.length) { return true; } // check for repeated letters with a new Set
} else if (str.length == 0) { return true; } // empty string is an isogram too
return false;
}