coffeescript - Check nested objects with an array of keys -


I have got an array with keys for a series of nested objects, I need to make sure that First, I set a value after that, there is an object. This code is working but only that I can be bothered to repeat it.

How can I do this again without the number of keys in the array n without switching this pomegranate? Goal [1]] = {} When 3 Objects [Goal [0]] [Goal [Target] [Target] [Goal [1] [Goal [1]] [target [0]] [target [0]] [target [1]] [target [2]] [goal] [4] if object [target [0]] [target [1] [Target] [target] [target] [target] [target] [target] [target] [target] [target] [target] [target] [target] [target] ] [Goal [1]] [goal [2]] [goal [3]] [goal [4]] is undefined object [goal [1]] [goal [2] [] [Goal [3]] [Goal [4]] = {} When 6 Object Objects [Goal [0]] [Goal [1]] [Goal [2]] [Goal [4]] [Goal [5] ] Undefined object is [goal [0]] [goal [1]] [target [2]] [target [3]] [target [4]] [target [5]] = {}

warning unwanted code from top of my head but should work (currently [T]? = {})

or more Javascripty version:

  Code> target.reduce ((o, t) - & gt; O [t]? = {}), Object   

does not pollute the scope with the first more legible, second and elegant (and current ). < / Div>

Comments