Complete the function scramble(str1, str2) that returns true if a portion of str1 characters can be rearranged to match str2, otherwise returns false.
Notes:
- Only lower case letters will be used (a-z). No punctuation or digits will be included.
- Performance needs to be considered
- Input strings
s1ands2are null terminated.
Examples
'rkqodlw', 'world' ==> True
'katas', 'steak' ==> False
My Code:
function scramble(str1, str2) {
let str = '';
for (i = 0; i < str2.length; i++) {
if (str1.includes(str2[i])) {
str1 = str1.replace(str2[i], '')
str += str2[i]
}
if (str === str2) return true
}
return false
}