Skip to content

Instantly share code, notes, and snippets.

@rakin92
Created September 5, 2019 04:13
Show Gist options
  • Save rakin92/721b065117c956cc4f0732575d43be6d to your computer and use it in GitHub Desktop.
Save rakin92/721b065117c956cc4f0732575d43be6d to your computer and use it in GitHub Desktop.
/**
* @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