我想在没有方法的同一个数组中找到一个元素的POSITIONS,一个算法......
示例:
var a = [1,2,2,1,4,5,6]
to display positions of 1 : position 0 and 3
to display positions of 2 : position 1 and 2
Run Code Online (Sandbox Code Playgroud)
到目前为止我做了什么:
function count(array,element){
while(element in array){
return array.indexOf(element);
}
}
Run Code Online (Sandbox Code Playgroud)