DEV Community

Discussion on: Daily Challenge #159 - Isogram

Collapse
 
robertobutti profile image
Roberto B. • Edited

I dropped some lines in Typescript.
Solution based on filter() and indexOf. indexOf returns the index of the first occurrence of the item in the array. So if a character appears the second time in the string, indexOf and index will be different.

function is_isogram(s: string): boolean {
    let a = s.toLowerCase().split("")
    return a.filter((char, index) => a.indexOf(char) !== index).length === 0
}

console.log("Dermatoglyphics:", is_isogram("Dermatoglyphics"))
console.log("aba:", is_isogram("aba"))
console.log("moOse:", is_isogram("moOse"))