Advertisement
EntropyStarRover

Odd

Jul 10th, 2019
151
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function oddOccurences(input) {
  2.     let wordsMap = new Map;
  3.  
  4.     let wordsArr = input.split(" ");
  5.     wordsArr = wordsArr.map(word => word.toLowerCase());
  6.  
  7.  
  8.     wordsArr.forEach(word => {
  9.         let count = 1;
  10.  
  11.         if (!wordsMap.has(word)) {
  12.             wordsMap.set(word, count);
  13.         }
  14.         else {
  15.             let currentQuantity = wordsMap.get(word);
  16.             currentQuantity++;
  17.             wordsMap.set(word, currentQuantity);
  18.         }
  19.  
  20.     });
  21.  
  22.     let arr = [...wordsMap];
  23.     let line = "";
  24.     arr.forEach(element => {
  25.         if (element[1] % 2 != 0) {
  26.             line += element[0] + " ";
  27.         }
  28.     });
  29.     console.log(line);
  30. }
Advertisement
RAW Paste Data Copied
Advertisement