Isograms: codewars kata confusion

  • Thread starter Thread starter shivajikobardan
  • Start date Start date
  • Tags Tags
    Confusion
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
7 replies · 2K views
shivajikobardan
Messages
637
Reaction score
54
TL;DR
codewars kata not passing all tests.
https://www.codewars.com/kata/54ba84be607a92aa900000f1/train/javascript
This is my code for it.
JavaScript:
function isIsogram(str) {
  let i, j;
  let str1 = str.toLowerCase();
  for (i = 0; i < str1.length; i++) {
    for (j = i + 1; j < str1.length; j++) {
      if (str1[i] === str1[j]) {
        return false;
      }
      else {
        return true;
      }
    }
  }
}
isIsogram("Dermatoglyphics");

My code isn't passing all tests, why? I feel this works fine.
 
Last edited:
Physics news on Phys.org
Well for one, the code seems to return unconditionally on the first pass of either loop.
 
Reply
  • Like
Likes   Reactions: pbuk
shivajikobardan said:
My code isn't passing all tests, why? I feel this works fine.
Which test is it not passing? Note I already know this, I am asking because YOU need to know; I don't need any help.

When you have identified it, step through the code in your head/on paper/in debug until you get to the point where it fails, or just log everything to the console and look for it.
 
pbuk said:
just log everything to the console and look for it.
there's no error in console.
 
shivajikobardan said:
there's no error in console.
I meant that you should log the progress of your loop to the console. This is how you debug code.
 
Reply
  • Like
Likes   Reactions: Halc