jacekwilczynski

mapKeys

Nov 17th, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// TEST 1
  2.  
  3. var input = {
  4.   'a': 1,
  5.   'b': 2,
  6.   'c': 3
  7. };
  8.  
  9. var capitalize = function(str) {
  10.   return str.toUpperCase();
  11. };
  12.  
  13. var output = mapKeys(input, capitalize);
  14.  
  15. /* output should be:
  16. {
  17.   'A': 1,
  18.   'B': 2,
  19.   'C': 3
  20. }
  21. */
  22.  
  23. /// TEST 2
  24.  
  25. var input = {
  26.   imie: 'Zbigniew',
  27.   nazwisko: 'Parzywoda'
  28.   rokUrodzenia: 1955,
  29.   pesel: '55021712345'
  30. };
  31.  
  32. var polishToEnglish = function(str) {
  33.   var dictionary = {
  34.     'imie': 'firstName',
  35.     'nazwisko': 'surname',
  36.     'rokUrodzenia': 'birthYear'
  37.   };
  38.   return dictionary[str] || str;
  39. };
  40.  
  41. var output = mapKeys(input, polishToEnglish);
  42.  
  43. /* output should be:
  44. {
  45.   firstName: 'Zbigniew',
  46.   surname: 'Parzywoda'
  47.   birthYear: 1955,
  48.   pesel: '55021712345'
  49. }
  50. */
Advertisement
Add Comment
Please, Sign In to add comment