在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/HTML/ seamless-immutable的使用問(wèn)題

seamless-immutable的使用問(wèn)題

現(xiàn)在有這么一段數(shù)據(jù)

let a = [{list:[1,2,3]},{list:[4,5,6]}];
let aIm = immutable(a);

我想把list數(shù)組中的每一項(xiàng)都加1,應(yīng)該怎么寫?

回答
編輯回答
默念

可以這樣做,用兩層reduce來(lái)實(shí)現(xiàn):


(() => {
  let a = [{list: [1, 2, 3]}, {list: [4, 5, 6]}]
  let aIm = Immutable(a)

  aIm = aIm.reduce((aIm, item, index) =>
    aIm.updateIn([index, 'list'], add), aIm)

  function add (arr) {
    return arr.reduce((arr, item, index) =>
      arr.updateIn([index], plus), arr)
  }

  function plus (x) {
    return x + 1
  }

  console.log(aIm)
})()
2017年6月10日 04:30
編輯回答
哎呦喂
a.map(x => {
    return x.list.map(y => y+1)
})
2018年5月7日 14:23
編輯回答
安若晴
let list = Immutable.fromJS([{list:[1,2,3]},{list:[4,5,6]}])
list.map(item => item.updateIn(['list'], list => list.map(n => ++n))).toJS()

clipboard.png

2018年4月11日 10:25