Referring to this picture, the first array is x-coordinate and second array is y-coordinate. The blue boxes will be the node number for each (x,y). if the point has been labelled before, it will remain with the same node number that was assigned to it previously. And if the point has not been labelled before and is new, it will be assigned a new node number :) For my attempt, I am trying to find the index of all mirror coordinates and the number of mirror coordinates present with the code below. However, I am unsure what the next step should be to get the value of the blue boxes in an array. This is in javascript. Any guidance will be appreaciated :)
for (let i=0;i<jaja 1;i ){
if ( (x_all[arr[m] i]==x_all[arr[m]-i]) ){
}
}
CodePudding user response:
This is a fairly straightforward 'zip' with an added map of previously seen points, here tracked in an object keyed by the JSON
string of each point, and retrieving/setting the next id using logical nullish assignment (??=).
const xs = [102, 152, 202, 252, 202, 152, 302, 10, 332, 10, 1];
const ys = [100, 50, 60, 70, 60, 9, 3, 2, 1, 2, 100];
let seen = {}, count = 1;
const result = xs.map((x, i) => {
const point = { x, y: ys[i] };
const id = (seen[JSON.stringify(point)] ??= count );
return { id, ...point };
})
console.log(result)
see more 'zip' discussion here: Javascript equivalent of Python's zip function