DEV Community

Cover image for JavaScript 🐲 challenges_2 βš”οΈ
Mahmoud EL-kariouny
Mahmoud EL-kariouny

Posted on β€’ Edited on

1

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

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (2)

Collapse
 
jonrandy profile image
Jon Randy πŸŽ–οΈ β€’
const isIsogram = str =>
  [...new Set([...str.toLowerCase()])].length == str.length
Enter fullscreen mode Exit fullscreen mode
Collapse
 
mahmoudessam profile image
Mahmoud EL-kariouny β€’

Excellent solution bro :)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

πŸ‘₯ Ideal for solo developers, teams, and cross-company projects

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay