Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function store(input) {
- let words = input
- .shift()
- .split(' ');
- let wordsCount = {};
- for (let word of words) {
- wordsCount[word] = 0;
- }
- for (let i = 0; i < input.length; i++) {
- if (wordsCount.hasOwnProperty(input[i])) {
- wordsCount[input[i]]++;
- }
- }
- let sorted = Object.entries(wordsCount).sort((firstPair, secondPair) => {
- let [firstWord, firstOccurence] = firstPair;
- let [secondWord, secondOccurence] = secondPair;
- return secondOccurence - firstOccurence;
- });
- sorted.forEach(element => {
- console.log(`${element.join(' - ')}`);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement