Javascript Codewars Problem: "Isograms"
- Get link
- X
- Other Apps
Codewars Problem and solution in Javascript
Objective:
In this challenge, we will solve the “Isograms” Codewars puzzle using javascript.
Problem statement:
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. It must return the display text as shown in the examples:
Examples:
Input : Dermatoglyphics
Output : true
Input : aba
Output: false
Input : moOse
Output : false // -- ignore letter case
Input : isogram
Output : true
Solution Hint:
we will create a character map from the given string and check if any character repeats or not and return true or false accordingly. Note: Remember to convert string to lower case to make it case insensitive.
For understanding characterMap, refer the post.
Solution:
function isIsogram(str){
var charMap={}
var strArr= str.toLowerCase().split('')
for(let el of strArr){
if(charMap[el]){
return false;
}
else
charMap[el]=1;
}
- Get link
- X
- Other Apps
Comments
Post a Comment