Skip to content

Commit

Permalink
Update instructions.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Cool-Katt committed Jul 15, 2024
1 parent 5de2c23 commit 0acf6e9
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions exercises/concept/coordinate-transformation/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# Instructions

Your design company has primarily been working with CSS transformations to build web pages. After some discussion, a decision is made
to start using JavaScript to perform some calculations dynamically. Some of your teammates are less experienced with JavaScript,
Your design company has primarily been working with CSS transformations to build web pages. After some discussion, a
decision is made
to start using JavaScript to perform some calculations dynamically. Some of your teammates are less experienced with
JavaScript,
so you decide to use a function closure to create reusable transformation for `{x, y}` coordinate pairs.

## 1. Translate the coordinates

Implement the `translate2d` function that returns a function making use of a closure to perform a repeatable 2d translation of a coordinate pair.
Implement the `translate2d` function that returns a function making use of a closure to perform a repeatable 2d
translation of a coordinate pair.

> In Geometry, [translation][wiki-translate] reffers to moving points, vectors or shapes the same distance in one
> direction. It can be interpreted as addition of a constant to every point.
```javascript
const moveCoordinatesRight2Px = translate2d(2, 0);
Expand All @@ -16,7 +22,11 @@ const result = moveCoordinatesRight2Px(4, 8);

## 2. Scale the coordinates

Implement the `scale2d` function that returns a function making use of a closure to perform a repeatable 2d scale of a coordinate pair.
Implement the `scale2d` function that returns a function making use of a closure to perform a repeatable 2d scale of a
coordinate pair.

> In geometry, uniform [scaling][wiki-scale] reffers to enlarging or shrinking vectors or shapes in the same
> diraction. It can be interpreted as multiplying every point by a constant (scaling factor).
> For this exercise, assume only positive scaling values.
Expand All @@ -28,7 +38,8 @@ const result = doubleScale(6, -3);

## 3. Compose transformation functions

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)'_.
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)'_.

```javascript
const moveCoordinatesRight2Px = translate2d(2, 0);
Expand All @@ -43,11 +54,14 @@ const result = composedTransformations(0, 1);

## 4. Save the results of functions

Implement the `memoizeTransform` function. It takes a function to _memoize_, then returns a new function that remembers the inputs to the supplied function so that the last return value can be "remembered" and only calculated once if it is called again with the same arguments.
Implement the `memoizeTransform` function. It takes a function to _memoize_, then returns a new function that remembers
the inputs to the supplied function so that the last return value can be "remembered" and only calculated once if it is
called again with the same arguments.

> Memoizing is sometimes used in _dynamic programming_.
> It allows for expensive operations to be done only once since their results are remembered.
> **Note** that in this exercise only the last result is remembered, unlike some solutions in dynamic programming that memoize _all_ results.
> **Note** that in this exercise only the last result is remembered, unlike some solutions in dynamic programming that
> memoize _all_ results.
```javascript
const tripleScale = scale2d(3, 3);
Expand All @@ -56,3 +70,7 @@ const memoizedScale = memoizeTransform(tripleScale);
memoizedScale(4, 3); // => [12, 9], this is computed since it hasn't been computed before for the arguments
memoizedScale(4, 3); // => [12, 9], this is remembered, since it was computed already
```

[wiki-translate]: https://en.wikipedia.org/wiki/Translation_(geometry)

[wiki-scale]: https://en.wikipedia.org/wiki/Scaling_(geometry)

0 comments on commit 0acf6e9

Please sign in to comment.