【发布时间】:2018-07-28 12:30:07
【问题描述】:
在不可变 Map 中动态更改键的最佳方法是什么?
// I have a map like this:
const names = Map({
rya: true,
mike: false,
});
// I receive this as inputs
const inputIndex = 0;
const inputLetter = n;
// What are the operations that i need to do here to get the expected output
// [?CODE?]
// I expect this as output:
const names = Map({
ryan: true,
mike: false,
});
到目前为止,我的解决方案似乎效率低下:
const namesEntrySeq = names.entrySeq();
const objectToModify = namesEntrySeq.get(inputIndex);
objectToModify[0] = objectToModify[0] + inputLetter;
const namesAsArray = namesEntrySeq.toArray();
namesAsArray[inputIndex] = objectToModify;
const names = Immutable.Map(namesAsArray);
一定有更优雅的方式吗?
【问题讨论】: