-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_file.js
62 lines (51 loc) · 1.45 KB
/
test_file.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Example One - Final
// With this array [blue_object_1, green_object_1, blue_object_2, red_object_1]
// Into this {"blue" => ['blue_object_1, blue_object_2'], "green" => [green_object_1], "red" => [red_object_1]}
var testArray = [
blue_object_1,
green_object_1,
blue_object_2,
red_object_1
];
// Initialize store
var testStore = {};
for(let i=0;i<testArray.length;i++){
if(testStore.hasOwnProperty(i.color)){
testStore[i.color].push(testArray[i])
}else {
var testContainer = [];
testContainer.push(testArray[i]);
testStore[i.color] = testContainer;
}
}
// Example Two - Final
// one.plus.two.equal
(function(){
'use strict';
var numbers = function(init_value){
var _steps = [];
self.initialize = function(){
_steps.push(init_value);
return init_value;
};
self.initialize();
self.plus = function(){
_steps.push(self._value);
_steps.push('plus');
return self;
};
self.equals = function(){
var result = 0;
for(let i=0;i<_steps.length;i++){
if(_steps[i] === 'plus')
result += (_steps[(i-1)] + _steps[(i+1)]);
if(_steps[i] === 'minus')
result += (_steps[(i-1)] - _steps[(i+1)])
}
return result;
};
};
var one = new numbers(1);
var two = new numbers(2);
console.log(one.plus().two());
})();