Isograms: codewars kata confusion

  • Thread starter Thread starter shivajikobardan
  • Start date Start date
  • Tags Tags
    Confusion
Click For Summary

Discussion Overview

The discussion revolves around a coding challenge from Codewars related to determining if a string is an isogram, which is a word in which no letter occurs more than once. Participants are examining a specific implementation of the solution in JavaScript and troubleshooting why it fails to pass all tests.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant shares their code for checking isograms and expresses confusion about why it fails tests.
  • Another participant points out that the code returns unconditionally on the first pass of either loop, suggesting a logical flaw.
  • A different participant encourages the original poster to identify which specific test is failing and to debug the code step by step.
  • There is a suggestion to log the progress of the loop to the console as a debugging method.
  • One participant mentions that there is no error in the console, indicating a misunderstanding of the debugging process.
  • A later reply emphasizes the importance of logging the loop's progress for effective debugging.
  • Another participant notes the existence of the Set object in JavaScript, which may be relevant to the discussion but does not directly address the original code issue.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the original code's correctness, and multiple viewpoints regarding debugging strategies and code logic are presented.

Contextual Notes

The discussion highlights potential limitations in the original code's logic, particularly regarding the unconditional return statements, but does not resolve these issues. There is also an emphasis on the need for effective debugging techniques.

Who May Find This Useful

Readers interested in JavaScript programming, debugging techniques, or coding challenges may find this discussion relevant.

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:
Technology news on Phys.org
Well for one, the code seems to return unconditionally on the first pass of either loop.
 
  • Like
Likes   Reactions: pbuk
Think about how many times you have check letters before you can return true.
 
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.
 
got it.
 
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.
 
  • Like
Likes   Reactions: Halc
Readers may be interested to know that JavaScript now has a Set object.
 
  • Informative
Likes   Reactions: Ibix

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
55
Views
7K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 97 ·
4
Replies
97
Views
9K
  • · Replies 3 ·
Replies
3
Views
2K