-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
228 lines (170 loc) · 5.68 KB
/
script.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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/* This is Techolution coding test.
Please, read carefully as this information can affect the results of this test.
- This test is built in such a way that you don't have to
use console.log or any debugging tool unless this is your preference.
The result will appear on the right as true or false.
- assignment.log is the method we wrote to output your results
in Result tab on the right. First parameter is what you would like to output
second parameter is a number representing test number and you don't need to change it.
- We also added automatic conversion of objects and arrays
to strings for '==' comparison purposes.
So if you see something like:
assignment.log(filterGreaterThan(d, 10) == '[123,16,11]', 4)
it doesn't mean your function should
return a sting representing array -
you can just return array or object in your code.
- Please, write your code strictly under [your code goes here] and nowhere else,
even if you think it's not the best place for it.
- Don't forget to hit 'Update' button in JSFiddle pannel to make sure your
changes are saved!
If you have any questions - please, contact me: pavel@techolution.com
*/
//#1 create code that will result the following console logs print out true
// add(a)(b) should return the sum of a + b
// [your code goes here]
function add(a,b) {
return a+b;
}
assignment.log(add(5,9) === 14, 1);
assignment.log(add(11,9) === 20, 1);
//#2 write code so that the console logs print out true
// flipKeyValue() should return a new object where keys and values are flipped
// i.e. {'Your Name': 'name', 'Your Last Name': 'lastName', '111.222': 'number'}
// and {'Your Name': 'name', 'Your Last Name': 'lastName', '111.222': 'number', '0': 'age'}
function flipKeyValue(frames) {
// [your code goes here]
var footDive = {};
for(var parries in frames) {
footDive[frames[parries]] = parries;
}
return footDive;
}
// console.log(flipKeyValue(b));
var b = {
name: 'Your Name',
lastName: 'Your Last Name',
number: '111.222'
}
// console.log(flipKeyValue(b));
assignment.log(flipKeyValue(b) == '{"Your Name":"name","Your Last Name":"lastName","111.222":"number"}' , 2)
var c = {
name: 'Your Name',
lastName: 'Your Last Name',
number: '111.222',
age: 0
}
assignment.log(flipKeyValue(c) == '{"0":"age","Your Name":"name","Your Last Name":"lastName","111.222":"number"}', 2)
//
// //#3 write code so that both console logs print out true
// // getFullName() should return a string where all property values of the object are concatinated and separated with ', '
//
var d = {
'firstName' : 'First Name',
'lastName': 'Last Name',
'getFullName': getFullName = function(dValues) {
// [your code goes here]
var fn, ln, concatValue;
dValues = Object.values(d);
dValues.pop();
fn = dValues[0];
ln = dValues[1];
return fn + ", " +ln
}
}
console.log(d.getFullName());
assignment.log(d.getFullName() === 'First Name, Last Name', 3);
var e = {
'firstName' : 'Second Name',
'lastName' : 'Second Last Name',
'getFullName' : getFullName = function(dValues) {
// [your code goes here]
var fn, ln, concatValue;
dValues = Object.values(e);
dValues.pop();
fn = dValues[0];
ln = dValues[1];
return fn + ", " +ln
}
}
console.log(e.getFullName());
assignment.log(e.getFullName() === 'Second Name, Second Last Name', 3);
//#4 write code so that console logs print out true
// filterGreaterThan(array, filter) should return a new array
// with all the values from initial array that are greater than filter
// i.e. [6, 10, 123, 16, 7, 8, 9, 11] and [123, 16, 11]
function filterGreaterThan(targetArray,filter) {
// [your code goes here]
// targetValue = 5;
// console.log(num);
// console.log(targetArray);
return targetArray > 10 ;
}
function filterGreaterThanFive(targetArray) {
return targetArray > 5 ;
}
function filterGreaterThanTen(targetArray) {
return targetArray > 10 ;
}
function letsMakeFilterGreatAgain(targetArray,filter) {
var filtered = targetArray.filter(filter);
console.log(filtered);
return filtered;
}
var d = [5, 6, 10, -1, 123, 1, 3, 16, 7, 8, 9, 11];
assignment.log(letsMakeFilterGreatAgain(d,filterGreaterThanFive) == '[6,10,123,16,7,8,9,11]', 4);
assignment.log(letsMakeFilterGreatAgain(d, filterGreaterThanTen) == '[123,16,11]', 4);
// //#5 write code so that console logs print out true
// // add(addValue) should return a new arrays where addValue
// // is added to each value of original array
// // i.e. [6, 7, 8, 9, 10] and [11, 12, 13, 14, 15]
//
// // [your code goes here]
// Array.prototype.add = function(qiymati,arrayInQuestion) {
// arrayInQuestion.forEach(
// function(numericalValue) {
// console.log(qiymati , numericalValue);
//
// });
// return;
// }
var addition = function(entry) {
// entry = 5;
// var e = [1, 2, 3, 4, 5];
e.array.forEach(function(item) {
// console.log(entry + item);
return entry + item;
})
};
var e = {
'array': [1, 2, 3, 4, 5],
'add': addition;
};
var numberFive = 5;
console.log(e.add(numberFive));
//
//
// console.log(e.add(1));
//
// function add(entry) {
// // entry = 5;
// var e = [1, 2, 3, 4, 5];
// e.forEach(function(item) {
// console.log(entry + item);
// return entry + item;
// })
//
// }
//
// add(1);
// add(5);
// add(10);
//
// add(5);
// console.log(e.add());
//
// var answer = e.greet();
// console.log(answer);
assignment.log(e.add(numberFive) == '[6,7,8,9,10]', 5);
// var d = [1, 2, 3, 4, 5];
// assignment.log(d.add(10) == '[11,12,13,14,15]', 5);
//