It looked pretty frank to me when I started, but for some reason I get an empty array every time I try to run the result on code tables. I hope you can help me determine what the problem is.
function alphabetPosition(text) { text.split(' ').join(''); var chari = ""; var arr = []; var alphabet = "abcdefghijklmnopqrstuvwxyz".split(''); for(var i = 0; i < text.len; i++){ chari = text.charAt(i).toLowerCase(); if(alphabet.indexOf(chari) > -1){ arr.push(alphabet.indexOf(chari)); } } return arr; } console.log(alphabetPosition("Hello World"));
My idea is to get the text from the parameter, then cross out the spaces. I created a variable for my empty array and create an alphabet string that I can execute later. In the for loop, I make each character lowercase, and if the character is in the string of the alphabet, its position falls into the array (arr). I appreciate your time.
source share