I have a function buildList with an array of numbers in argument. I also have 11 elements which are numbers and i want to know if these elements exists in the array and if one element doesn't exist i push it in another array.
Actually it looks like that:
public static buildList(numbers[]) {
const newArray= [];
if (numbers.find(element => element === ELEMENT_ONE) === undefined ) {
newArray.push(ELEMENT_ONE);
}
if (numbers.find(element => element === ELEMENT_TWO) === undefined ) {
newArray.push(ELEMENT_TWO);
}
....
}
My current intuition was to create a new array with the 11 elements and do a for each but i'm not pretty sure the performance will be better... Is there any way to improve this code ? because i do the same things for the 11 elements