Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input){
- let searched = input.shift().split(' ');
- let matched = new Map();
- for (const word of searched) {
- let matches = input.filter(el=>{
- return el === word;
- });
- matched.set(word,matches.length);
- }
- Array.from(matched)
- .sort((a,b)=>{
- return b[1] - a[1];
- }).forEach(pair=>{
- let word = pair[0];
- let count = pair[1];
- console.log(`${word} - ${count}`);
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment