Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 嵌套数组中的Ramda索引_Javascript_Arrays_Currying_Ramda.js - Fatal编程技术网

Javascript 嵌套数组中的Ramda索引

Javascript 嵌套数组中的Ramda索引,javascript,arrays,currying,ramda.js,Javascript,Arrays,Currying,Ramda.js,我一直在努力与Ramda打交道,并且到目前为止我都很喜欢它,但是我正在努力解决一些看起来很基本的问题(如果这是重复的话,我很抱歉) 我有一个数组(代表一个游戏板) 玩家使用匹配的牌来构建移动,例如: const move = [[7, 4], [7, 5], [6, 5]] const mapWithIndex = R.addIndex(R.map) const addIndices = mapWithIndex((i, row) => mapWithIndex((j, tile) =&

我一直在努力与Ramda打交道,并且到目前为止我都很喜欢它,但是我正在努力解决一些看起来很基本的问题(如果这是重复的话,我很抱歉)

我有一个数组(代表一个游戏板)

玩家使用匹配的牌来构建移动,例如:

const move = [[7, 4], [7, 5], [6, 5]]
const mapWithIndex = R.addIndex(R.map)
const addIndices = mapWithIndex((i, row) => mapWithIndex((j, tile) => j + i))
我想映射移动坐标与不同值匹配的分幅(例如,这些坐标处的
1
s将变成
-1

我知道Ramda可以用R.addIndex来扩充R.map:
const-mapWithIndex=R.map(R.addIndex)
这样
mapWithIndex((I,value)=>//do something))
就可以访问每个磁贴的索引,但我知道如何将所有参数传递到最低级别

我甚至不能把I和j加在一起,我试过这样的方法:

const move = [[7, 4], [7, 5], [6, 5]]
const mapWithIndex = R.addIndex(R.map)
const addIndices = mapWithIndex((i, row) => mapWithIndex((j, tile) => j + i))
但是调用这个函数会返回一个函数数组

我错过了什么?任何帮助都将不胜感激:)

有两个问题:

  • 内部的
    mapWithIndex
    需要访问
    ,这样它就可以在平铺中进行迭代
  • 示例代码中的值和索引参数已反转
这应该做到:

const mapWithIndex = R.addIndex(R.map);
const addIndices = mapWithIndex((row, i) => mapWithIndex((tile, j) => j + i)(row));

太棒了,非常感谢,我不知道为什么我认为索引参数是第一位的。我想我的下一个问题是,我怎样才能把它分解成更小的单位,它们可以作为参数传递给玩家移动数组以及I,j?