Created
September 5, 2019 04:13
-
-
Save rakin92/721b065117c956cc4f0732575d43be6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {string} ransomNote | |
* @param {string} magazine | |
* @return {boolean} | |
*/ | |
const canConstruct = function (ransomNote, magazine) { | |
const asciiPossible = 'abcdefghijklmnopqrstuvwxyz'; | |
if(ransomNote.length > magazine.length){ | |
return false | |
} | |
for (let i = 0; i < asciiPossible.length; i++) { | |
let re = new RegExp(asciiPossible[i], "g"); | |
if (ransomNote.replace(re, '').length !== magazine.replace(re, '').length) { | |
return false | |
} | |
} | |
return true | |
}; | |
console.log(canConstruct("a", "b")); | |
console.log(canConstruct("aa", "ab")); | |
console.log((canConstruct("aa", "aab")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment