Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input){
- let collection = input.slice(0);
- let words = new Map();
- let uniqWords = Array.from(new Set(input));
- for (const word of uniqWords) {
- let currentSet = collection.filter(item=> item === word );
- words.set(word,currentSet.length);
- }
- Array.from(words)
- .sort((a,b)=>{
- return b[1] - a[1];
- }).forEach(pair=>{
- console.log(`${pair[0]} -> ${pair[1]} times`);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment