-
Notifications
You must be signed in to change notification settings - Fork 0
/
7kyu.js
48 lines (37 loc) · 1.22 KB
/
7kyu.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
function array (f){
let g= [];
for (i=0;i<f.length;i++){
g.push(parseFloat(f[i]))}
return g;
}
console.log(array(["1.1","2.2"]))
function michaelPays(costs) {
return parseFloat((costs<5?costs:costs/3<10?costs-(costs/3):costs-10).toFixed(2))
}
function square (a){
let el = "";
for (let i = 1; i <= a-1; i++) {
for (let j = 1; j <= a; j++) {
el += "+";
}
el += "\n"
}
return el + '+'.repeat(a)
}
console.log(square(8));
function move_zeros(arr,isRight) {
let array = [];
let array1 =[];
for(i=0;i<arr.length;i++){
if(isRight===true||isRight===undefined){
const f = arr[i]>0? array.push(arr[i]):array1.push(arr[i]);
}if (isRight===false){
const f = arr[i]>0? array1.push(arr[i]):array.push(arr[i]);
}
}
const f = array.concat(array1);
return f
}
console.log(move_zeros([12, 0, 10, 0, 8, 12, 7, 6, 0, 4, 10, 12, 0], true), [12, 10, 8, 12, 7, 6, 4, 10, 12, 0, 0, 0, 0]);
console.log(move_zeros([12, 0, 10, 0, 8, 12, 7, 6, 0, 4, 10, 12, 0], false), [0, 0, 0, 0, 12, 10, 8, 12, 7, 6, 4, 10, 12]);
console.log(move_zeros([12, 0, 10, 0, 8, 12, 7, 6, 0, 4, 10, 12, 0]), [12, 10, 8, 12, 7, 6, 4, 10, 12, 0, 0, 0, 0]);