2
说我有一个对象,它看起来是这样的 -深克隆对象
data =
a: 1
b: 2
c:
d: 3
e: 4
f:
g: 4
h:
i: 9
我想写这相当基本复制这个对象深深但其最小的10多
更换数的函数a: 10
b: 20
c:
d: 30
e: 40
f:
g: 40
h:
i: 90
我想用lodash或下划线来写最少量的代码。这是我目前所做的 -
execute = (key) ->
#console.log typeof key, key
if typeof key is 'number'
return key * 10
result = {}
_.forIn key, (value, name) ->
result[name] = execute value
return result
请建议一些优雅和干净的东西。
更新:
通过lodash LIB会经过我发现了一个更好的办法 -
_.cloneDeep data,(value) -> value * 10 if typeof value is 'number'
我想要一个更好的解决方案。 – Tushar