-2

I'm stuck on this CodeWars problem where I check to see if a letter is repeated within a word and I'm having a problem checking for equality. The letters appear to be all strictly not equal as the loop iterates.

function isIsogram(str){
  var split = str.toLowerCase().split('');
  var result = true;

  for (var i = 0; i < str.length; i++){
    for (var j = i+1; j < str.length; j++){
      if (split[i] !== split[i][j]) {
          console.log(split[i]+ " -> "+ split[j] );
        } 
        else {
           console.log("They are equal");
        }            
      }
    }
 }
isIsogram( "abca" )
Sani Huttunen
  • 23,620
  • 6
  • 72
  • 79
  • 1
    What is `split[i][j]` supposed to be? `split` is not a 2-dimensional array. – Barmar Jan 06 '18 at 01:53
  • 1
    That should just be `split[j]`. BTW, there's no need to convert the string to an array, since you can access string elements with `str[i]`. – Barmar Jan 06 '18 at 01:54
  • FYI you can achieve this with a regular expression `'abcba'.match(/([\s\S])(?=[\s\S]*?\1)/g); // ["a", "b"]` – Paul S. Jan 06 '18 at 02:07

1 Answers1

0

Comparing split[i] to split[i][j], but logging split[j] to console instead. Do you want compare it to split[j] instead?

This looks more intuitive:

function isIsogram(str){
    var str2 = str.toLowerCase();
    var result = true;

    for (var i = 0; i < str2.length; i++){
        for (var j = i+1; j < str2.length; j++){
            if (str2[i] !== str2[j]) {
                console.log(str2[i]+ " -> "+ str2[j] );
            } 
            else {
                console.log("They are equal");
            }            
        }
    }
}
isIsogram( "abca" )
LuFFy
  • 8,799
  • 10
  • 41
  • 59
Ozgur Amac
  • 16
  • 2
  • Welcome to Stack Overflow! This is really a comment, not an answer. With a bit more rep, [you will be able to post comments](//stackoverflow.com/privileges/comment). For the moment I've added the comment for you, and I'm flagging this post for deletion. – Barmar Jan 06 '18 at 01:56