-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex5.js
106 lines (73 loc) · 1.6 KB
/
ex5.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
// #1
function gummyBears( e, d, g ) {
return e + d + g
}
gummyBears(3,7,8)
// #2
var str = "animation"
var other = "joehoe"
//you can select characters of a string by using array-notation
function let (string) {
return string[string.length-1]
}
console.log(let(str))
console.log(let(other))
// #3
function cubey( x ) {
return Math.pow ( x, 3)
}
console.log(cubey(4))
// perhaps this method was meant or this??
// function power(base, exponent) {
// if (exponent == 0)
// return 1;
// else
// return base * power(base, exponent - 1);
// }
// console.log(power(2, 3));
// #4
function reString( str ) {
var newString = "";
for (var i = str.length - 1; i >= 0; i--) {
newString += str[i];
}
return newString;
}
reString( 'oyasumi')
// #5
var keys = ['Tokyo', 'Jeju']
var values = ['sushi', 'abalone']
function twoArrays( a, b ) {
//create object
var object = {}
// loop through arrays and store values and keys in object
for (var i = 0; i < a.length; i++) {
object[keys[i]] = values[i];
}
return object
}
console.log(twoArrays(keys, values))
// #6
// create object
var ob = {
T: 'woop',
J: 'bleep',
F: 'zoof'
};
// create function with an object with 2 empty arrays where you want to store your data in
function transformobject( obj ) {
//create a different object
var bob = {
keys: [],
values: []
}
//
// loop through the object that been put in the function and push the keys AND the values in bob.keys and bob.values
for(var key in obj) {
bob.keys.push(key);
bob.values.push(obj[key])
}
// return the object
return bob
}
transformobject(obj)