-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiterable.js
84 lines (73 loc) · 1.69 KB
/
iterable.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
const iterable = {
[Symbol.iterator]() {
let step = 0;
const iterator = {
next() {
step++;
if (step === 1) {
return { value: "This", done: false };
} else if (step === 2) {
return { value: "is", done: false };
} else if (step === 3) {
return { value: "iterable", done: false };
}
return {
value: undefined,
done: true
};
}
};
return iterator;
}
};
var iterator = iterable[Symbol.iterator]();
console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());
function removeProperty(obj, prop) {
if (Object.keys(obj).includes(prop)) {
delete obj[prop];
return true;
} else {
return false;
}
}
removeProperty(
{
prop: true,
noProp: false
},
"prop"
);
function formatDate(userDate) {
const reserseDate = userDate
.split("/")
.reverse()
.join();
const monthDayReserse = reserseDate.split(",");
[monthDayReserse[1], monthDayReserse[2]] = [
monthDayReserse[2],
monthDayReserse[1]
];
if (monthDayReserse[1].length < 2) {
monthDayReserse[1] = 0 + monthDayReserse[1];
} else if (monthDayReserse[2].length < 2) {
monthDayReserse[2] = 0 + monthDayReserse[2];
}
return monthDayReserse.join("");
// format from M/D/YYYY to YYYYMMDD
}
console.log(formatDate("12/31/2014"));
function FirstFactorial(num) {
let count = num;
let total = 1;
while (count > 0) {
total *= count;
count--;
}
// code goes here
return total;
}
// keep this function call here
console.log(FirstFactorial(readline()));