Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(arr) {
- let obj = {};
- for (let i = 0; i < arr.length; i++) {
- let line = arr[i].split(" -> ");
- let city = line[0];
- let product = line[1];
- let price = line[2].split(" : ").reduce((a, b) => a * b);
- if (typeof obj[city] === "undefined") {
- obj[city] = {};
- }
- obj[city][product] = price;
- }
- for (let key in obj) {
- console.log(`Town - ${key}`);
- for (let value of obj[key]) {
- for (let objElementKeyKey in value) {
- console.log(`$$$${objElementKeyKey} : ${value[objElementKeyKey]}`);
- }
- }
- }
- }
- solve(['Sofia -> Laptops HP -> 200 : 2000',
- 'Sofia -> Raspberry -> 200000 : 1500',
- 'Sofia -> Audi Q7 -> 200 : 100000',
- 'Montana -> Audi Q7 -> 200000 : 1',
- 'Montana -> Qgodas -> 20000 : 0.2',
- 'Montana -> Chereshas -> 1000 : 0.3']
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement