Im really struggling with the 3rd task in the coordinate transformation exercise. In which i am asked to:
Combine two transformation functions to perform a repeatable transformation. This is often called function composition , where the result of the first function ‘f(x)’ is used as the input to the second function ‘g(x)’
I think understand concept behind function composition. chaining together functions by return a function within a function. however I am still stuck with how to implement them given the code:
const moveCoordinatesRight2Px = translate2d(2, 0); const doubleCoordinates = scale2d(2, 2); const composedTransformations = composeTransformation( moveCoordinatesRight2Px, doubleCoordinates ); const result = composedTransformations(0, 1); // result => [4, 2]
so far in my journey ive tried to visualize what is happening with the code to get an understanding of whats happening so i can figure out where to start, however i cant seem to visualize what the code is actually doing. So i cant even begin to figure out how to implement a solution
Does anyone have any resources regarding function composition they can refer me? All the resources I’ve found so far reinforce the conceptual idea but i cant seem to move beyond that. I also have a feeling that my inability to grasp this is because im not 100% with closures.