-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01.furniture.js
More file actions
40 lines (29 loc) · 808 Bytes
/
01.furniture.js
File metadata and controls
40 lines (29 loc) · 808 Bytes
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
function furniture(text) {
let finalSum = 0;
console.log("Bought furniture:");
for (let line of text) {
if (line === "Purchase") {
break;
}
let pattern = />>(?<name>[A-za-z]+)<<(?<price>\d+(.\d+)?)!(?<amount>\d+)/;
let result = pattern.exec(line);
if (result !== null) {
let name = result.groups["name"];
let price = result.groups["price"];
let amount = result.groups["amount"];
finalSum += Number(price) * Number(amount);
console.log(name);
}
}
console.log(`Total money spend: ${finalSum.toFixed(2)}`);
}
furniture([
">>Laptop<<312.2323!3",
">>TV<<300.21314!5",
">Invalid<<!5",
">>TV<<300.21314!20",
">>Invalid<!5",
">>TV<<30.21314!5",
">>Invalid<<!!5",
"Purchase",
]);