js 把二维数组改成四象限图用的格式
function quadrantSort(arr) {
let quadrant1 = [];
let quadrant2 = [];
let quadrant3 = [];
let quadrant4 = [];
arr.forEach(point => {
if (point[0] > 0 && point[1] > 0) {
quadrant1.push(point);
} else if (point[0] 0) {
quadrant2.push(point);
} else if (point[0]
quadrant3.push(point);
} else if (point[0] > 0 && point[1]
quadrant4.push(point);
}
});
return {
quadrant1,
quadrant2,
quadrant3,
quadrant4
};
}
const points = [[-1, 1], [1, 2], [-1, -1], [1, -1]];
const sortedPoints = quadrantSort(points);
console.log('Quadrant 1:', sortedPoints.quadrant1);
console.log('Quadrant 2:', sortedPoints.quadrant2);
console.log('Quadrant 3:', sortedPoints.quadrant3);
console.log('Quadrant 4:', sortedPoints.quadrant4);