Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function wordsTracker(array) {
- let searchedWords = array[0].split(' ');
- let targetWords = array.splice(1, array.length - 1);
- let wordObj = {};
- for (let word of searchedWords) {
- wordObj[word] = 0;
- for (let element of targetWords) {
- if (element === word) {
- wordObj[word] += 1;
- }
- }
- }
- let sortedEntries = Object.entries(wordObj).sort((a, b) => b[1] - a[1])
- for (let entry of sortedEntries) {
- console.log(`${entry[0]} - ${entry[1]}`)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement