How to find if stringB contains all of the values of stringA?
Imagining you want to make a new string (stringB) out of stringA, when you take a value from stringA, it'll disappear from stringA, you can't use it twice.
So if stringB has repeated values, but stringA only has one of that value, then the program should return false.
Example Input:
stringA = "A B C D"
stringB = "B B C D"
Example Output:
false
Because stringA only has one "B".
Example Input:
stringA = "apple banana orange mango"
stringB = "banana orange"
Example Output:
true
Here is what I have, but it return true when it should've returned false can anyone tell me what is wrong with my logic or what should the solution be? Thanks!
let arrayContainsArray = (a, b) => {
let a_array = a.split(" ")
let b_array = b.split(" ")
for(let i = 0; i < b_array.length; i++) {
if (a_array.includes(b_array[i])) {
let index = a_array.indexOf(b_array[i])
a_array.splice(index, 1)
} else {
return false
}
return true
}
}
console.log(arrayContainsArray('two times three is not four', 'two times two is four'));
stringAandstringBactually strings and not arrays?arrayContainsArray('B C D', 'B B C D')?trueorfalse?