JSFiddle - React, Tailwind, and code Playground
by momenelkamri
JavaScript
const arr = ['hello', 'test', 'two words']
const string = 'this is two test';//<-- "words two" different order
var newarr2 = string.split(" ");
var newarr = arr.map(o=>o.split(" "));
function flatten(arr) {
return arr.reduce(function (flat, toFlatten) {
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
}, []);
}
newarr = flatten(newarr);
newarr.forEach(o=>{
console.log(o+" ---> "+(newarr2.indexOf(o) != -1))
})