Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve2(str) {
- str = str.split(' ')
- .map(x => x.toLowerCase());
- const wordCounter = {};
- // initialize the wordCounter
- for (const el of Array.from(new Set([...str]))) {
- wordCounter[el] = 0;
- }
- // populate the wordCounter
- for (const word of str) {
- if (wordCounter.hasOwnProperty(word)) {
- wordCounter[word]++;
- }
- }
- // sort and print
- const countOdd = [...Object.entries(wordCounter)].filter(([k, v]) => v % 2 === 1); // [[c#, 3], ...]
- console.log(countOdd.map(e => e[0]).join(' '));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement