Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onTheWayToAnnapurna(input) {
- let output = {};
- let curCommand = input.shift();
- while (curCommand !== 'END') {
- let [command, store, items] = curCommand.split('->');
- if (command === 'Add') {
- if (!Object.keys(output).includes(store)) {
- output[store] = []
- }
- items.split(',').forEach(element => {
- output[store].push(element);
- });
- } else if (command === 'Remove') {
- if (Object.keys(output).includes(store)) {
- delete(output[store]);
- }
- }
- curCommand = input.shift();
- }
- output = Object.entries(output);
- output.sort((a, b) => {
- if (a[1].length > b[1].length) {
- return -1;
- } else if (a[1].length < b[1].length) {
- return 1;
- } else {
- if (a[0] > b[0]) {
- return -1;
- } else if (a[0] < b[0]) {
- return 1
- }
- }
- });
- console.log('Stores list:');
- output.forEach(element => {
- console.log(element[0]);
- element[1].forEach(element1 => {
- console.log(`<<${element1}>>`);
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment