Guest User

Untitled

a guest
Dec 12th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. var gifts = [
  2. {name:"partridge", type : "bird"},
  3. {name:"turtle dove", type : "bird"},
  4. {name:"french hen", type : "bird"},
  5. {name:"calling bird", type : "bird"},
  6. {name:"gold ring", type : "jewlery"},
  7. {name: "goose", type:"bird"},
  8. {name: "swan", type: "bird"},
  9. {name: "milk maid", type: "person"},
  10. {name: "lady dancing", type: "person"},
  11. {name: "leaping lord", type: "person"},
  12. {name: "piper", type: "person"},
  13. {name: "drummer", type: "person"}
  14. ];
  15. function numberOfTotalGifts(day=12){
  16. var sum = 0;
  17. for(let n = 0; n < day; n++){
  18. sum += 0.5*n*(n+1);
  19. }
  20. return sum
  21. }
  22.  
  23. function totalTypesOfGifts(day = 12){
  24. var sums = {};
  25. for(let n = 0; n < day; n++){
  26. for(let g = 0; g < n+1; g++){
  27. if(sums.hasOwnProperty(gifts[g].type) == false){
  28. sums[gifts[g].type] = g+1;
  29. }else{
  30. sums[gifts[g].type] += g+1;
  31. }
  32. }
  33. }
  34. return sums;
  35. }
  36.  
  37. function totalGiftsByName(day = 12){
  38. var sums = {};
  39. for(let n = 0; n < day; n++){
  40. for(let g = 0; g < n+1; g++){
  41. if(sums.hasOwnProperty(gifts[g].name) == false){
  42. sums[gifts[g].name] = g+1;
  43. }else{
  44. sums[gifts[g].name] += g+1;
  45. }
  46. }
  47. }
  48. return sums;
  49. }
Add Comment
Please, Sign In to add comment