I am trying to solve a Javascript challenge on Codewars.
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
My effort is below:
function isIsogram(str) {
var arr = str.split("");
var seen = {};
var out = [];
var length = arr.length;
var j = 0;
for(var i = 0; i < length; i++) {
var item = arr[i].toLowerCase;
if(seen[item] !== 1) {
seen[item] = 1;
out[j++] = item;
}
}
console.log(out.toString.toLowerCase);
console.log(str.toLowerCase);
if (out.toString.toLowercase === str.toLowerCase) {
return true;
}
else {
return false;
}
}
In codewars the result of my
console.log(out.toString.toLowerCase); is undefined
and the result of
console.log(str.toLowerCase); is [Function: toLowerCase].
This means my solution always evaluates to false.
I would appreciate any help to point me in the right direction or highlight my errors instead of giving me the solution so I can learn more effectively. Thanks!