Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var gifts = [
- {name:"partridge", type : "bird"},
- {name:"turtle dove", type : "bird"},
- {name:"french hen", type : "bird"},
- {name:"calling bird", type : "bird"},
- {name:"gold ring", type : "jewlery"},
- {name: "goose", type:"bird"},
- {name: "swan", type: "bird"},
- {name: "milk maid", type: "person"},
- {name: "lady dancing", type: "person"},
- {name: "leaping lord", type: "person"},
- {name: "piper", type: "person"},
- {name: "drummer", type: "person"}
- ];
- function numberOfTotalGifts(day=12){
- var sum = 0;
- for(let n = 0; n < day; n++){
- sum += 0.5*n*(n+1);
- }
- return sum
- }
- function totalTypesOfGifts(day = 12){
- var sums = {};
- for(let n = 0; n < day; n++){
- for(let g = 0; g < n+1; g++){
- if(sums.hasOwnProperty(gifts[g].type) == false){
- sums[gifts[g].type] = g+1;
- }else{
- sums[gifts[g].type] += g+1;
- }
- }
- }
- return sums;
- }
- function totalGiftsByName(day = 12){
- var sums = {};
- for(let n = 0; n < day; n++){
- for(let g = 0; g < n+1; g++){
- if(sums.hasOwnProperty(gifts[g].name) == false){
- sums[gifts[g].name] = g+1;
- }else{
- sums[gifts[g].name] += g+1;
- }
- }
- }
- return sums;
- }
Add Comment
Please, Sign In to add comment