Hi i am checking to see if str2 characters are in str1 characters. If there are duplicates it causes problems.
My idea was to remove the character(currentValue) in str1 once it has been used once. I chose the replace method for this. However ,it is not working. May i know why?
is it because currentValue can only be called within the map function?
thanks
split1.replace(currentValue, "");
function scramble(str1, str2) {
//1) create a variable that stores the word
let stored = "";
let bool = false;
//2) split str1 to an array
const split1 = str1.split("");
//2 split str 2 into ther own strings values
repeated = 0;
let split2splice = split2;
//3) map over the array for each str2 value
split2.map(function(currentValue, index, arr) {
if (split1.includes(currentValue)) {
stored += currentValue;
bool = true;
console.log(stored);
split1.replace(currentValue, "");
} else {
bool = false;
console.log(bool);
stored = "";
}
});
//4) if it has, add it to stored4
//5) if at any point there isnt a letter, return false
// 5a) if there are two same values in str2 and only 1 same value in str1, it means it will still return false.
//need to find a way to return false if there are two
//you have to delete the character in str1 once its been used once
//6) once str1 has returned the value you need to alter str1 and delete the value that was just passed
//7) if the map is all ok, return true to stored
if (stored.length === str2.length) {
bool = true;
} else {
bool = false;
}
return bool;
}
scramble("comaehisa", "commas");