Skip to content

Commit 83fac4b

Browse files
homework-5 fixed concat
1 parent 1f3528c commit 83fac4b

File tree

1 file changed

+21
-7
lines changed
  • js-core/homeworks/homework-5/src

1 file changed

+21
-7
lines changed

js-core/homeworks/homework-5/src/main.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,17 @@ let arr2 = [
3535
9
3636
];
3737
function moveZeroToEnd(arr) {
38+
let newArr = [];
39+
let arrWithnumber = [];
3840
for(let i=0;i<arr.length;i++){
3941
let index = arr[i];
4042
if(index===0){
41-
arr.splice(i,1);
42-
arr.push(index);
43+
newArr.push(index);
44+
continue
4345
}
46+
arrWithnumber.push(index);
4447
}
45-
return arr
48+
return arrWithnumber.concat(newArr);
4649
}
4750
console.log(moveZeroToEnd(arr1));
4851
console.log(moveZeroToEnd(arr2));
@@ -118,12 +121,23 @@ capMe(['jo', 'nelson', 'jurie'])
118121
*/
119122

120123
function random(arr) {
124+
let lastElem = arr[arr.length - 1];
125+
let firstElem = arr[0];
126+
let step = (lastElem - firstElem)/arr.length;
127+
for(let i = 0;i<arr.length;i++){
128+
let elem = arr[i];
129+
let nextElem = arr[i+1];
130+
if(elem + step != nextElem){
131+
return elem + step
132+
}
133+
}
134+
return
121135
}
122136

123-
random([1, 3, 5, 9]);
124-
random([0, 8, 16, 32]);
125-
random([0, 16, 24, 32]);
126-
random([4, 6, 8, 10]);
137+
console.log(random([1, 3, 5, 9]));
138+
console.log(random([0, 8, 16, 32]));
139+
console.log(random(([0, 16, 24, 32])));
140+
console.log(random([4, 6, 8, 10]));
127141

128142
/*
129143
Задача с собеседований*

0 commit comments

Comments
 (0)