Code snippet doesn't seem to allow console.table
, so here it is with console.log
instead:
var points=[ {name:"A", x:6, y:8}, {name:"B", x:-6, y:2}, {name:"C", x:4, y:-4} ]; function intersection(pntsArr) { var returnValue=[]; for(var i=0; i<pntsArr.length-1; i++) { for(var j=i+1; j<pntsArr.length; j++) { returnValue.push( { name:pntsArr[i].name+"->"+pntsArr[j].name, x:pntsArr[i].x, y:pntsArr[j].y } ); returnValue.push( { name:pntsArr[j].name+"->"+pntsArr[i].name, x:pntsArr[j].x, y:pntsArr[i].y } ); } } return returnValue; } console.log(intersection(points));
Should work with any number of points.
Could produce duplicate points, depending on input.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.