Last active
December 18, 2017 09:38
-
-
Save arjan0307/4525bd6a4632d38d8e11497c0db1189f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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