I'm working with an array:
main = [{
data: x,
numberField: 1;
}, { data: y,
numberField: 2;
}, { data: x,
numberField: 3;
},
{ data: z,
numberField: 4;
},
{ data: q,
numberField: 5;
}]
fixedElements = [3, 5]
My goal is to achieve the following:
fixedElements.includes(a.numberField) - fixedElements.includes(b.numberField)
The purpose of this comparison is to determine if two incoming values are present in array a without sorting them, but sort the remaining elements. However, TypeScript throws an error when attempting this operation.
left/right-hand side of the argument needs to be of type any or number.
Initially, my sorting function looks like this:
sort(a,b) {
if(a.numberField > b.numberField)
return -1
if(a.numberField < b.numberField)
return 1;
}
As I wanted to prioritize checking if a or b are part of the fixedElements array and position them last. Is there a better way to approach this?