Find all indices of a given element in sorted form

Run Settings
LanguageJavaScript
Language Version
Run Command
function indexesOfElement(array, target){ let smCount=0; let occurence=0; for(let x of array){ if(x<target){ smCount++; } else if(x===target){ occurence++; } } let result=[] if(occurence==0){ return [] } else{ while(occurence--){ result.push(smCount); smCount++; } } return result; } console.log(indexesOfElement([1, 2, 5, 2, 3],3))
Editor Settings
Theme
Key bindings
Full width
Lines