Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function oddOccurrences(input) {
- let oddWords = {};
- let sentence = input.split(' ');
- for (let word of sentence) {
- let key = word.toLowerCase();
- if (oddWords.hasOwnProperty(key)) {
- oddWords[key]++;
- } else {
- oddWords[key] = 1;
- }
- }
- let sortedWords = Object.entries(oddWords).filter(entry => entry[1] % 2 !== 0)
- sortedWords.sort((a, b) => b[1] - (a[1]));
- let result = sortedWords.map(entry => entry[0]);
- console.log(result.join(' '));
- }
Advertisement
Add Comment
Please, Sign In to add comment