audipower

objectFactory - object composition

Nov 1st, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function objectFactory(str) {
  2.    
  3.     let arr = JSON.parse(str).reduce((acc, cur) => {
  4.         return acc = Object.assign(acc, cur)
  5.     },{})
  6.     return arr;
  7. }
  8.  
  9. objectFactory(
  10.     `[
  11.         {"canMove": true},
  12.         {"canMove":true, "doors": 4},
  13.         {"capacity": 5}
  14.     ]`
  15. )
  16.  
  17. objectFactory(`[{"canFly": true},{"canMove":true, "doors": 4},{"capacity": 255},{"canFly":true, "canLand": true}]`)
Advertisement
Add Comment
Please, Sign In to add comment