在ramda.js中,fromPairs是否改变了元素的顺序?
In ramda.js, does fromPairs change the order of elements?
我收到大量对:[number, {number,number, big array of numbers}]
首先,我将我的主要货币对添加到数组的开头:
prepend([target[0], {count : target[1].length, overall : target[1].length, items:target[1]}]),
接下来我做:
Promise.all([
to_file_json(
token.user_id,
'connections_data',
JSON.stringify(
fromPairs(r[0])
))...
而且我可以在文件中间的某处找到我的主要货币对。
所以我的问题是,fromPairs
可以更改顺序吗?如果是,我该怎么做才能防止这种情况发生?
编辑:
补充信息:
1)r
变量对应[[number, Friends][], Float64Array[]]
2) target
变量对应[number,number[]]
3) 我添加的元素的开头,它总是最大的,并且不知何故位于文件的中间。
"136444868":{"count":304,"overall":304,"items":[19363,234566,290677,1375661,2030175,2131497,2593602,2596894,2816890,2869895,3170377,3437884,3486703,3504543,4046799,4235623,5366101.....
4) 好友类型:
interface Friends {
count:number,
overall:number,
items:number[]
};
示例数据
{
"19363":{"count":5,"overall":3088,"items":[51177198,53119509,136035431,209482119,216378147]}
,"234566":{"count":6,"overall":6803,"items":[290677,3504543,23180680,75311610,178479726,196401211]}
,"290677":{"count":19,"overall":2213,"items":[234566,5686439,7873089,11175816,13726459,20697213,23180680,27419631,55209039,74493674,75311610,125041200,133272552,139307068,159591583,168386810,173599247,178429642,189097165]}
,"1375661":{"count":0,"overall":76,"items":[]},"2030175":{"count":14,"overall":86,"items":[2596894,6507568,11681736,17736119,49557638,117771194,127144880,141523415,147264238,153044182,156925389,160656334,223530741,262311445]},"2131497":{"count":16,"overall":301,"items":[13598979,15682478,20357560,20869716,27419631,30869837,33650605,40129023,68976427,88146695,90648231,101105191,118193129,145163503,216503667,387266562]},
我预计问题是您执行 prepend
时没有从列表中后面的位置删除该元素。
那么您最终可能会得到一些数据,例如:
[
[ 2131497, { count: 16, overall: 301, items: [ /* .. * ] } ], // duplicate
[ 19363, { count: 5, overall: 3088, items: [ /* .. * ] } ],
[ 234566, { count: 6, overall: 6803, items: [ /* .. * ] } ],
[ 290677, { count: 19, overall: 2213, items: [ /* .. * ] } ],
[ 1375661, { count: 0, overall: 76, items: [ /* .. * ] } ],
[ 2030175, { count: 14, overall: 86, items: [ /* .. * ] } ],
[ 2131497, { count: 16, overall: 301, items: [ /* .. * ] } ] // duplicate
]
然后,当您执行 fromPairs
时,较新的版本将覆盖较早的版本,并且它将最终回到列表中的原始位置,根据文档中的这一行:
If a key appears in multiple pairs, the rightmost pair is included in the object.
但是......即使你修复了这个问题,你仍然不会得到你想要的行为,因为这个对象属性 iteration order specification, which says that integer keys of an object are iterated first, in numeric order, before the non-integer keys. Axel Rauschmayer has a very readable description。
这些复杂性是 Ramda(免责声明:我是作者之一)尚未创建 foldObj
实现的原因之一。
我收到大量对:[number, {number,number, big array of numbers}]
首先,我将我的主要货币对添加到数组的开头:
prepend([target[0], {count : target[1].length, overall : target[1].length, items:target[1]}]),
接下来我做:
Promise.all([
to_file_json(
token.user_id,
'connections_data',
JSON.stringify(
fromPairs(r[0])
))...
而且我可以在文件中间的某处找到我的主要货币对。
所以我的问题是,fromPairs
可以更改顺序吗?如果是,我该怎么做才能防止这种情况发生?
编辑:
补充信息:
1)r
变量对应[[number, Friends][], Float64Array[]]
2) target
变量对应[number,number[]]
3) 我添加的元素的开头,它总是最大的,并且不知何故位于文件的中间。
"136444868":{"count":304,"overall":304,"items":[19363,234566,290677,1375661,2030175,2131497,2593602,2596894,2816890,2869895,3170377,3437884,3486703,3504543,4046799,4235623,5366101.....
4) 好友类型:
interface Friends {
count:number,
overall:number,
items:number[]
};
示例数据
{
"19363":{"count":5,"overall":3088,"items":[51177198,53119509,136035431,209482119,216378147]}
,"234566":{"count":6,"overall":6803,"items":[290677,3504543,23180680,75311610,178479726,196401211]}
,"290677":{"count":19,"overall":2213,"items":[234566,5686439,7873089,11175816,13726459,20697213,23180680,27419631,55209039,74493674,75311610,125041200,133272552,139307068,159591583,168386810,173599247,178429642,189097165]}
,"1375661":{"count":0,"overall":76,"items":[]},"2030175":{"count":14,"overall":86,"items":[2596894,6507568,11681736,17736119,49557638,117771194,127144880,141523415,147264238,153044182,156925389,160656334,223530741,262311445]},"2131497":{"count":16,"overall":301,"items":[13598979,15682478,20357560,20869716,27419631,30869837,33650605,40129023,68976427,88146695,90648231,101105191,118193129,145163503,216503667,387266562]},
我预计问题是您执行 prepend
时没有从列表中后面的位置删除该元素。
那么您最终可能会得到一些数据,例如:
[
[ 2131497, { count: 16, overall: 301, items: [ /* .. * ] } ], // duplicate
[ 19363, { count: 5, overall: 3088, items: [ /* .. * ] } ],
[ 234566, { count: 6, overall: 6803, items: [ /* .. * ] } ],
[ 290677, { count: 19, overall: 2213, items: [ /* .. * ] } ],
[ 1375661, { count: 0, overall: 76, items: [ /* .. * ] } ],
[ 2030175, { count: 14, overall: 86, items: [ /* .. * ] } ],
[ 2131497, { count: 16, overall: 301, items: [ /* .. * ] } ] // duplicate
]
然后,当您执行 fromPairs
时,较新的版本将覆盖较早的版本,并且它将最终回到列表中的原始位置,根据文档中的这一行:
If a key appears in multiple pairs, the rightmost pair is included in the object.
但是......即使你修复了这个问题,你仍然不会得到你想要的行为,因为这个对象属性 iteration order specification, which says that integer keys of an object are iterated first, in numeric order, before the non-integer keys. Axel Rauschmayer has a very readable description。
这些复杂性是 Ramda(免责声明:我是作者之一)尚未创建 foldObj
实现的原因之一。