-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsk.js
48 lines (31 loc) · 823 Bytes
/
tsk.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//Given an array of random integers,
//move all the zeros in the array to the end of the array.
let array=[1,2,0,1,0,0,3,6,0,0,183,68,0];
function sArray(array){
var newArray=[];
var counter=0;
for(var i =0;i<=array.length-1;i++){
if (array[i]===0){
newArray.push(array[i]);
}
counter++
}
return newArray;
}
let result=sArray(array);
//console.log(result);
function kArray(array){
var firstArray=[]
var counter=0;
for(var i =0;i<=array.length-1;i++){
if (array[i]!==0){
firstArray.push(array[i])
}
counter++
}
return firstArray;
}
let result1=kArray(array);
//console.log(result1);
var children = result1.concat(result);
console.log(children);