-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs_nonsense.html
More file actions
67 lines (53 loc) · 1.4 KB
/
js_nonsense.html
File metadata and controls
67 lines (53 loc) · 1.4 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
<!DOCTYPE html>
<meta charset = "utf-8">
<script>
'use strict';
console.log('hello');
function divide(a, b) {
if (b > a) {
[a, b] = [b, a];
}
if (a % b == 0) {
this.result = a / b;
this.history = `${a} / ${b} = ${this.result}`;
} else {
this.result = [a, b];
this.history = `${b} doesn't go into ${a}`;
}
}
function add(a, b) {
this.result = a + b;
this.history = `${a} + ${b} = ${this.result}`;
}
function new_list(numbers, operation, index1, index2) {
numbers.splice(index1, 1);
numbers.splice(index2 - 1, 1);
return numbers.concat(operation.result);
}
var numbers = [1, 2, 3, 4, 5, 6];
var index1 = 2;
var index2 = 4;
var something = new_list(numbers, new add(numbers[index1], numbers[index2]), index1, index2);
console.log(something);
var addh = new add(9,6);
console.log(addh.history);
var out = new divide(2, 6);
console.log(out.history);
var obj_list = [];
for (var i = 0; i < numbers.length; i++) {
for (var j = i + 1; j < numbers.length; j++) {
console.log(new divide(numbers[i], numbers[j]).history);
}
}
function chain(numbers, operation, chain = []) {
this.chain = chain;
for (var i = 0; i < numbers.length; i++) {
for (var j = i + 1; j < numbers.length; j++) {
this.chain.push(new operation(numbers[i], numbers[j]))
}
}
}
var numbers2 = [1,2,3,4,5,6];
var test = new chain(numbers2, divide);
console.log(test.chain);
</script>