Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve (arr) {
- let words = arr.shift().split(' ');
- let obj = {};
- let arr2 = [];
- arr.forEach(el => words.includes(el) ? obj[el] = (obj[el] || 0) + 1 : false);
- // console.log(obj);
- let sortedArr = Object.entries(obj).sort((a, b) => b[1] === a[1] ? a[0].localeCompare(b[0]) : b[1] - a[1]);
- // console.log(sortedArr);
- for (let [key, value] of sortedArr) {
- console.log(`${key} - ${value}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement