Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.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对X和Y坐标进行排序_Javascript_Sorting_Ramda.js - Fatal编程技术网

Javascript 使用Ramda对X和Y坐标进行排序

Javascript 使用Ramda对X和Y坐标进行排序,javascript,sorting,ramda.js,Javascript,Sorting,Ramda.js,我有一个表单数组: [ { i: 'text', layout: {x: 1, y: 0} } { i: 'text', layout: {x: 0, y: 0} } { i: 'text', layout: {x: 1, y: 1} } ] 我想使用ramda包对数组进行排序 我已经到了第一个到达Y的地步-- 请建议如何对x和y进行排序- {x: 0, y: 0} {x: 1, y: 0} {x: 1, y: 1} 用于使用多个比较器进行排序 const xySort = R.

我有一个表单数组:

[
  { i: 'text', layout: {x: 1, y: 0} }
  { i: 'text', layout: {x: 0, y: 0} }
  { i: 'text', layout: {x: 1, y: 1} }
]
我想使用ramda包对数组进行排序

我已经到了第一个到达Y的地步--

请建议如何对x和y进行排序-

{x: 0, y: 0}
{x: 1, y: 0}
{x: 1, y: 1}
用于使用多个比较器进行排序

const xySort = R.sortWith([
  R.ascend(R.path(['layout','x'])),
  R.ascend(R.path(['layout','y']))
])
用于使用多个比较器进行排序

const xySort = R.sortWith([
  R.ascend(R.path(['layout','x'])),
  R.ascend(R.path(['layout','y']))
])

看起来你想用

这是:


看起来你想用

这是:

var list = [
  { i: 'first', layout: {x: 1, y: 1} },
  { i: 'second', layout: {x: 1, y: 0} },
  { i: 'third', layout: {x: 0, y: 1} },
];

var xySort = R.sortWith([
  R.ascend(R.path(['layout', 'x'])),
  R.ascend(R.path(['layout', 'y'])),
]);

console.log(xySort(list));