-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlgorithm_3.js
More file actions
132 lines (110 loc) · 1.82 KB
/
Algorithm_3.js
File metadata and controls
132 lines (110 loc) · 1.82 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//PART ONE//
function a(x,y){
return 5;
}
console.log(a(5,5))
//Output = 5
function a(x,y){
z = []
z.push(x);
z.push(y);
z.push(5);
console.log(z);
return z;
}
b = a(2,2)
console.log(b);
console.log(a(6,8));
//Output = [2,2,5], [6,8,5]
function a(x){
z = [];
z.push(x);
z.pop();
z.push(x);
z.push(x);
return z;
}
y = a(2);
y.push(5);
console.log(y);
//Output = [2,2,5]
function a(x){
if(x[0] <x [1]) {
return true;
}
else {
return false;
}
}
b = a([2,3,4,5])
console.log(b);
//Output = true
function a(x){
for(var i=0; i<x.length; i++){
if(x[i] > 0){
x[i] = “Coding”
}
}
console.log(a([1,2,3,4]))
//Output = [Coding, Coding, Coding, Coding]
function a(x){
for(var i=0; i<x.length; i++){
if(x[i] > 5){
x[i] = “Coding”
}
else if(x[i] < 0){
x[i] = “Dojo”
}
}
console.log(a([5,7,-1,4]))
//Output = [Coding, Coding, Dojo, Coding]
function a(x){
if(x[0] > x[1]) {
return x[1];
}
return 10;
}
b = a([5,10])
console.log(b);
//Output = 10
function sum(x){
sum = 0;
for(var i=0; i<x.length; i++){
sum = sum + x[i];
console.log(sum);
}
return sum;
}
//Output = undefined because length of x is never defined.
///PART TWO///
function printAverage(x){
sum = 0;
for(i=0; i<x.length; i++){
sum+=x[i];
}
avg = sum / x.length;
return avg;
}
y = printAverage([1,2,3]);
console.log(y);
y = printAverage([2,5,8]);
console.log(y);
function returnOddArray(){
var arr=[];
for (var i = 0; i<=255; i++){
if(i%2 !== 0);
console.log(arr[i]);
}
return arr;
}
y = returnOddArray();
function squareValue(x){
for(var i=0; i<x.length; i++){
x[i] = x[i]*x[i]
}
return x
}
y= squareValue([1,2,3]);
console.log(y);
y=squareValue([2,5,8]);
console.log(y);