Skip to content

Instantly share code, notes, and snippets.

@arjan0307
Last active December 18, 2017 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arjan0307/4525bd6a4632d38d8e11497c0db1189f to your computer and use it in GitHub Desktop.
Save arjan0307/4525bd6a4632d38d8e11497c0db1189f to your computer and use it in GitHub Desktop.
window.CO2M ||= {}
window.CO2M.UTIL =
_defineProperty: (obj, key, value) ->
if key of obj
Object.defineProperty obj, key,
value: value
enumerable: true
configurable: true
writable: true
else
obj[key] = value
obj
arrayToNestedHash: (arr) ->
last_element = true
reducer = (acc, item) ->
if last_element
last_element = false
item
else
CO2M.UTIL._defineProperty {}, item, acc
arr.reduceRight reducer, {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment