let's say I have a class Part with 3 properties x,y,z:
class Part {
constructor(x, y, z) {
this.x = x
this.y = y
this.z = z
}
createNewFromParts(...parts){
}
}
I want that the createNewFromParts function that will get x parts and will find a constant number for each part to duplicate his properties with, so after all of the parts will be duplicated, the sum of each property value from all of the parts will the closest to the original part property. I also want to log the percentage of success. The percentage of success will be calculated by all of the 3 properties together regard to the previous values, not by individuals.
for example :
const whole = new Part(4,6,10);
const part1 = new Part(1,2,4);
const part2 = new Part(2,2,3);
in this example this is easy: multiply part1 in 1 and part2 in 2 and it the result of the addition will be (5,6,10) which is probebly the best match.
Lets say There will be something like this:
const whole = new Part(32,10,27);
const part1 = new Part(10,7,15);
const part2 = new Part(15,5,22);
How will I found the constants to duplicate each part to get the best match?
I want to findan algorithm that will find a constant for each part to duplicate with to get the best match which is the closest to the original.
Appriciate the help :)