-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathes6.js
63 lines (52 loc) · 1.27 KB
/
es6.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
/* how to write clean code in javascript using es6 syntax. */
// template literals.
function yell(name) {
return `Come here ${name.toUpperCase()}`;
}
console.log(yell("hendrix"));
// arrays.
const names = ["Hendrix", "Ombonyo", "Sing", "Developer"];
function alphabetizeNames() {
return [...names].sort();
}
console.log(alphabetizeNames());
let staff = [
{ name: " Hendrix", position: "Developer" },
{ name: "Ogutu", position: "Auditor" },
];
function getAuditor(staff) {
//return staff.filter((member) => member.position === "Auditor");
}
console.log(getAuditor());
const getPosition = staff.filter((val) => val.position === "Auditor");
console.log(getPosition);
let stringNames = staff.toString();
console.log(stringNames);
const game1 = {
player: "Jim Jonas",
hits: 2,
runs: 1,
errors: 0,
};
const game2 = {
player: "Jim Jonas",
hits: 3,
runs: 0,
errors: 1,
};
const total = {};
const stats = Object.keys(game1);
//console.log(stats);
for (let i = 0; i < stats.length; i++) {
const stat = stats[i];
//console.log(stat);
if (stat !== "player") {
total[stat] = game1[stat] + game2[stat];
}
}
console.log(total);
const sections = ["contact", "shipping"];
function displayShipping(sections) {
return sections.indexOf("shipping") > -1;
}
console.log(displayShipping());