JavaScript šŸ² challenges_2 āš”ļø

mahmoudessam

Mahmoud EL-kariouny

Posted on March 24, 2023

JavaScript šŸ² challenges_2 āš”ļø

Isograms

  • An isogram is a word that has no repeating letters consecutive or non-consecutive.
  • Implement a function that determines whether a string that contains only letters is an isogram.
  • Assume the empty string is an isogram.
  • Ignore letter case.

Examples:

  • "Dermatoglyphics" --> true
  • "aba" --> false
  • "moOse" --> false (ignore letter case)

Task URL

My solution:

function isIsogramOne(str) {

    let strLower = str.toLowerCase(); // convert to lowercase
    let charArr = strLower.split(''); // split into array 
    let result = []; // create empty array to store unique characters

    for (let i = 0; i < charArr.length; i++) { // loop through array
        if (result.indexOf(charArr[i]) === -1) { // if chraacter is not in array
            result.push(charArr[i]); // push character to array 
        }
    }
    return result.length === charArr.length;
}
Enter fullscreen mode Exit fullscreen mode

Another solution:

function isIsogramTow(str) {
    return str.toLowerCase().split('').filter((item, index, array) =>
        array.indexOf(item) === index).length === str.length;
}
Enter fullscreen mode Exit fullscreen mode
10 JavaScript Games to learn-Totally Cool & Fun šŸš€āœØšŸ”„

šŸŽ„

Connect with Me šŸ˜Š

šŸ”— Links

linkedin

twitter

šŸ’– šŸ’Ŗ šŸ™… šŸš©
mahmoudessam
Mahmoud EL-kariouny

Posted on March 24, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related