Alphabet symmetry HELP

challenge : https://www.codewars.com/kata/alphabet-symmetry/train/javascript
Can’t seem to debug the IF condition. i need your help!
my code:

function solve(arr){  
  console.log(arr)
let alphabets = ["A","B","C","D","E", "F", "G", "H", "I","J", "K", "L", "M", "N","O", "P", "Q", "R", "S", "T","U", "V", "W","X", "Y", "Z"];
let positionArr = [];

for ( let i = 0; i < arr.length; i++) { 
let incr = 0;
for (let j = 0; j < arr[i].length; j++ ) { 
  
  for (let n = 0; n < alphabets.length; n++) { 
    if (arr[i][j].toUpperCase()  === alphabets[n] ) { 
      incr++;
    }
  }
}
positionArr.push(incr);
}
console.log(arr[0][1].toUpperCase())
return positionArr;


};



solve(["abode","ABc","xyzD"])
// [4,3,1])

could maybe also post the challenge instructions? codewars doesn’t always load depending on device
it will much help to receive better help

  • your code
  • th challenge instructions verbatim
  • what you think the challenge instructions ask you to do in your own words

challenge instructions verbatim:

I think ill have to count the number of correct matching alphabets in the array elements. its like matching the actual alphabet order. like got eg. “abode” the correct number of matches is 4 because a starts first in the alphabet order and b second, d fouth and e 5th. as for “o” he’s at the very back. same goes for the other words in the array.
you can see
///[4,3,1] i typed at the bottom of my code as the expected answer.

please use quote tags to quote something, if you use backticks for text blocks it become not readable easily

now please explain to me what each line of your code is doing

I’m trying to match the alphabets in the standard alphabetical order and if it matches, i increment by 1. that’s the n loop. once i’m done with n loop, i go back out to the j loop to go to the next alphabet of the word in the array. and once j loop is done. i push all the incremental points to the array as the first number which denotes how many alphabets has matched the alphabetical standard order in the first word. then after pushing, i go to the most outer loop ( i ) and i++, which gets me to the next word in the array and then repeat.

your n loop will loop through all the alphabet so it will find for sure a match, and so you will find the counter having just the length of the string
what’s the condition for which the counter should increase?

1 Like

i don’t think there’s anything wrong with the loops or the code in general. just the if condition.

are you sure it’s just the if condition? look my last message

Thanks lol I solved it :smiley:

function solve(arr){  
  console.log(arr)
let alphabets = ["A","B","C","D","E", "F", "G", "H", "I","J", "K", "L", "M", "N","O", "P", "Q", "R", "S", "T","U", "V", "W","X", "Y", "Z"];
let positionArr = [];

for ( let i = 0; i < arr.length; i++) { 
let incr = 0;
for (let j = 0; j < arr[i].length; j++ ) { 
  
  for (let n = 0; n < alphabets.length; n++) { 
    if (arr[i][j].toUpperCase()  === alphabets[j] ) { 
      incr++;
      break;
    }
 
  }
}
positionArr.push(incr);
}
console.log(arr[0][1].toUpperCase())
return positionArr;


};



solve(["abode","ABc","xyzD"])
// [4,3,1])

why do you even have the n loop if you don’t use the n variable anywhere?

to break out of the n loop when i found my match though i could just remove the loop and the break altogether. lel

if you don’t mind can you help me out on this? String constructor - how can i pass?
looks like no one knows the answer yet and i certainly have no idea how to print strings without actually writing them down

I would just go through every string in the list with ‘for (i of )’ then with a for loop go through every char and change it to char code. If it is capital later i would subtract 65 (‘A’ in char code 65) or if it is small letter subtract 97. Then check result with for loop index (ex: i). If it match then we have found a match.Counting every match for every string we could solve this kata with less code and more efficient way. Just my initial thought.

thanks but i solved it with charcode already