I have these two arrays :
Original Array :
$arr_1=['disappear','rising','filled','decades];
User Array:
$arr_2=['disappear','filled','filled','decade];
this.indexesAttention=[];
$arr_1.forEach(x=>{
//concat two arrays
this.indexesAttention=[...this.indexesAttention,
...this.checkValue(x)]
});
checkValue(variable:string):number[]
{
return this.arr_2
.map((x,index)=>x.trim()==variable.trim()?index:-1)
.filter(x=>x!=-1) //only want the index>>-1
}
These should return the matching indexes in this case it should return [0,2] indexes because they are matching but in my case it is returning 0,2,1,3
[ngStyle]="(indexesAttention.indexOf(i)<0) ? {'border-color':'red','color':'red'} : show_answer === false ? {'border-color': 'black','color':'black'} : {'border-color': 'green','color':'green'}"
Any solution to resolve this issue, Thanks
arr1 = ['disappear','rising','filled','decades'];
arr2 = ['disappear','filled','filled','decade'];
constructor(){
const a = this.arr2.map((e,k) => {
const i = this.arr1.indexOf(e);
return k == i?i:-1;
}).filter(e => e != -1)
const rs = [...new Set(a)]; //output [0, 2]
}