I want to check if all of the audio file names in unorderedPhrases
array exist in the result
array that contains the URLs. if there are all exist return true
and if-else return false
.
Here is what I've tried. I don't know why it returns false
all the times!?
let result = [
"https://example.com/test/unordered/i was sent to earth to protect you_A/i was sent.mp3",
"https://example.com/test/unordered/i was sent to earth to protect you_A/to earth.mp3",
"https://example.com/test/unordered/i was sent to earth to protect you_A/to protect you.mp3",
];
const unorderedPhrases = [
'i was sent',
'to earth',
'to protect you'
];
function checkResults(){
return unorderedPhrases.every(r=> result.includes(r));
}
console.log(checkResults())
The above code should return true because all the audio files in unorderedPhrases
exist in the result
array.
if we have this array then it should return false
:
const unorderedPhrases = [
'i was sent',
'to earth',
];
You need another level of nesting - checking if the
result
array includes the phrase won't work (unless a phrase exactly matches one of theresult
items), because you need to search inside each string of theresult
array: