let main = "i am really calm at this moment";
let sub = "am this";
function missingWords () {
let mainArr = main.split(" ");
let subArr = sub.split(" ");
return mainArr.toLowerCase().filter( x => !subArr.toLowerCase.includes(x));
};
console.log(missingWords());
Asked
Active
Viewed 902 times
0

Spectric
- 30,714
- 6
- 20
- 43

One of Stones
- 37
- 4
-
Hi. Does these help you? https://stackoverflow.com/questions/18480351/how-to-use-javascript-for-string-words-comparision https://stackoverflow.com/questions/18050932/detect-differences-between-two-strings-with-javascript – Dhana D. Aug 29 '21 at 19:42
2 Answers
0
Arrays don't have a toLowerCase()
function. If you want to make all elements in the array lowercase, you should first convert the string to lowercase, then split by a space.
let main = "i am really calm at this moment";
let sub = "am this";
function missingWords() {
let mainArr = main.toLowerCase().split(" ");
let subArr = sub.toLowerCase().split(" ");
return mainArr.filter(x => !subArr.includes(x));
};
console.log(missingWords());

Spectric
- 30,714
- 6
- 20
- 43
0
I do not see any reason to split both of strings. You can use 'includes' also on string and not only on array.
function missingWords(mainString,subString) {
const lowerMainString = mainString.toLowerCase();
const lowerSubString = subString.toLowerCase();
return lowerMainString.split(" ").filter(x => !lowerSubString.includes(x));
};
missingWords("i am really calm at this moment", "am this");

zordon
- 186
- 9