Lodash打字稿 - 将多个阵列组合到一个单个数组中,并对每个数组进行计算
我有一个记录< string,number [] []>并试图对这些值进行计算。
一个示例输入:
const input1 = {
key1: [
[2002, 10],
[2003, 50],
],
};
const input2 = {
key1: [
[2002, 20],
[2003, 70],
],
};
const input3 = {
key1: [
[2002, 5],
[2003, 60],
],
};
对于每个键,对于特定年份,我想
year => input1 + input2 - input3
// output: 2002 => 25, 2003 => 60
对此进行以下操作,我一直在使用Lodash/fp。
map(a => a.map(nth(1)))(map('key1')([input1, input2]))
// [[10, 50], [20, 70], [5, 60]]
有没有办法以某种方式传递输入并在它们上迭代,并以某种方式获得回调函数以获取执行计算的值。
我尝试了zip
,zipwith
,但没有到达任何地方。
在这种情况下,我能做什么线索?
感谢您的帮助。
I have a Record<string, number[][]> and trying to perform calculation over these values.
An example input:
const input1 = {
key1: [
[2002, 10],
[2003, 50],
],
};
const input2 = {
key1: [
[2002, 20],
[2003, 70],
],
};
const input3 = {
key1: [
[2002, 5],
[2003, 60],
],
};
For each key, and for the specific year I want to do the following
year => input1 + input2 - input3
// output: 2002 => 25, 2003 => 60
For this I have been playing around with lodash/fp.
map(a => a.map(nth(1)))(map('key1')([input1, input2]))
// [[10, 50], [20, 70], [5, 60]]
is there a way to somehow pass the inputs and iterate over them, and somehow get a callback function to get the values to perform the calculation.
I tried zip
, zipWith
but didn’t get to anywhere with them.
Any clue what I can do in this instance?
Thank you for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
_。frompairs
方法获得一个对象,然后使用_。Mergewith
添加和减去对象。You could get an object with
_.fromPairs
method and then use_.mergeWith
to add and subtract.