I have two arrays, one with a text with more words and the other with the text that I should compare, the problem is that there is a word that appears twice in each array so when I run the code it repeats itself in the new array, when it should appear according to the order of array to validate
This is my code:
var taskInstructions = ["Fix a bug and something something remote",
"Must push the new version to the cloud"];
var actualTask = "Fix a bug and push the new version to the remote";
//como taskInstructions es un array lo cambio a string para despues
//volverlo a array, solo para que sea un solo elemento, hago lo mismo
//con el otro array
taskInstructions = taskInstructions.toString();
taskInstructions = taskInstructions.replace(',', ' ');
taskInstructions = taskInstructions.split(' ');
actualTask =actualTask.split(' ');
var jaredTask=[];
for(i=0; i < actualTask.length; i++ ){
for (n=0; n <= taskInstructions.length; n++){
if(actualTask[i] == taskInstructions[n]){
jaredTask.push(taskInstructions[n]);
}
}
}
//lo convierto otras vez para quitar las ','
jaredTask =jaredTask.toString();
var change = /,/g;
jaredTask = jaredTask.replace(change , ' ');
//el resultado muestra la palabra 'the' repetida de a 2 veces
console.log(jaredTask);