Javascript 2nd-Assignment related query

Below is a Javascript assignment-2nd question.
“Write a program to search if a number exists in an array. If the number exists then return the position. If it exists multiple time then return an array with all the positions. If the number doesn’t exist then return -1;”
I’m confused what to execute whether should I execute one statement or all three conditions in the output. Please give me description about this question sir…
@kashif-ta-fsr

1 Like

1-Initialize an array
2-Fill the array with every index of target element.
3- If at last array.length==0, fill -1 in it, then return, else return the array.

Maybe that is what question is asking to do. Would be better if you have provided method defination as well.

Thank you.
Can we use ternary operator in this question instead of if , if else ??

1 Like

Definitely. I was just telling the approach. We can have many ways to implement a single approach. BTW, I usually prefer ternary over if else

1 Like

Yeah! ternary operator is the good way.
Thank you.

1 Like