-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercise-4.js
81 lines (69 loc) · 1.22 KB
/
exercise-4.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
// exercise 1 splice
var bio = [
'0001',
'Roman Alamsyah',
'Bandar Lampung',
'21/05/1989',
'Membaca'
];
function dataHandling2(bio) {
bio.splice(1, 2, 'Roman Alamsyah Elsharawy', 'Provinsi Bandar Lampung');
bio.splice(4, 2, 'Pria', 'SMA Internasional Metro');
}
dataHandling2(bio);
console.log(bio);
// exercise 2 split
var splitResult = bio[3].split('/');
var month = Number(splitResult[1]);
switch (month) {
case 1:
month = 'Januari';
break;
case 2:
month = 'Februari';
break;
case 3:
month = 'Maret';
break;
case 4:
month = 'April';
break;
case 5:
month = 'Mei';
break;
case 6:
month = 'Juni';
break;
case 7:
month = 'Juli';
break;
case 8:
month = 'Agustus';
break;
case 9:
month = 'September';
break;
case 10:
month = 'Oktober';
break;
case 11:
month = 'November';
break;
case 12:
month = 'Desember';
break;
}
console.log(month);
// exercise 3 sort
var arrySorting = splitResult.sort(function(a, b) {
return b - a;
});
console.log(arrySorting);
// exercise 4 join
splitResult = bio[3].split('/');
var joinResult = splitResult.join('-');
console.log(joinResult);
// exercise 5 slice
var name = bio[1];
var sliceResult = name.slice(0, 15);
console.log(sliceResult);