Day 19 challenge is checking a letter duplication in a string.
To solve this a string also must be sorted
. If there are some characters duplication in a single string return false
otherwise return true
For example,
A string effg
will return false
because there are 2 letter f
.
But the string ace
will return true
since there is no letter duplication.
There is the JavaScript Solution
function alphabetSubsequence(str) {
// If letters NOT in ascending order and detect duplication return false
let result = str.split('').map( (val, index) => (str.charCodeAt(index) >= str.charCodeAt(index+1)) ? false : true);
// if result for ALL value are TRUE, return true, otherwise return false
return result.every( val => val == true);
}
Top comments (0)