-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctionExample.js
More file actions
62 lines (42 loc) · 1.19 KB
/
functionExample.js
File metadata and controls
62 lines (42 loc) · 1.19 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
function addition(x, y) {
return x + y;
}
function subtraction(x, y) {
return x - y;
}
function multiplication(x, y) {
return x * y;
}
function division(x, y) {
return x / y;
}
function operation(callBack, a, b) {
return callBack(a, b);
}
console.log(operation(addition, 5, 3));
console.log(operation(subtraction, 5, 3));
console.log(operation(multiplication, 5, 3));
console.log(operation(division, 6, 3));
function getMedian(arr1, arr2) {
const merged = arr1.concat(arr2);
merged.sort((a, b) => a - b);
const length = merged.length;
const mid = Math.floor(length / 2);
if (length % 2 === 0) {
return (merged[mid - 1] + merged[mid]) / 2;
} else {
return merged[mid];
}
}
const array1 = [23, 45, 12, 67];
const array2 = [56, 78, 90, 11];
console.log(getMedian(array1, array2));
function wordToDictionary(word) {
const result = {};
const lower = word.toLowerCase();
for (let char of lower) {
result[char] = lower.split(char).length - 1;
}
return result;
}
console.log(wordToDictionary("Femi go to schOOl"));