maymunskoa

02. Odd Occurrences (Assoc Arrays)

Mar 6th, 2020
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input){
  2.  
  3.     let match = new Array;
  4.     let collection = input.split(' ').map(word=>word.toLowerCase());
  5.     let uniqueSet = Array.from(new Set(collection));
  6.  
  7.     for (const word of uniqueSet) {
  8.         let matched = collection.filter(item=>item === word);
  9.         if(matched.length % 2 !==0){
  10.             match.push(word);
  11.         }
  12.     }
  13.     console.log(match.join(' '));
  14.    
  15. }
Advertisement
Add Comment
Please, Sign In to add comment