44// the @ts -check directive. It will give you helpful autocompletion when
55// implementing this exercise.
66
7+ /**
8+ * @typedef {function (number, number): [number, number] } CallbackType
9+ */
10+
711/**
812 * Create a function that returns a function making use of a closure to
913 * perform a repeatable 2d translation of a coordinate pair.
1014 *
1115 * @param {number } dx the translate x component
1216 * @param {number } dy the translate y component
1317 *
14- * @returns {function } a function which takes an x, y parameter, returns the
18+ * @returns {CallbackType } a function which takes an x, y parameter, returns the
1519 * translated coordinate pair in the form [x, y]
1620 */
1721export function translate2d ( dx , dy ) {
@@ -25,7 +29,7 @@ export function translate2d(dx, dy) {
2529 * @param {number } sx the amount to scale the x component
2630 * @param {number } sy the amount to scale the y component
2731 *
28- * @returns {function } a function which takes an x, y parameter, returns the
32+ * @returns {CallbackType } a function which takes an x, y parameter, returns the
2933 * scaled coordinate pair in the form [x, y]
3034 */
3135export function scale2d ( sx , sy ) {
@@ -36,10 +40,10 @@ export function scale2d(sx, sy) {
3640 * Create a composition function that returns a function that combines two
3741 * functions to perform a repeatable transformation
3842 *
39- * @param {function } f the first function to apply
40- * @param {function } g the second function to apply
43+ * @param {CallbackType } f the first function to apply
44+ * @param {CallbackType } g the second function to apply
4145 *
42- * @returns {function } a function which takes an x, y parameter, returns the
46+ * @returns {CallbackType } a function which takes an x, y parameter, returns the
4347 * transformed coordinate pair in the form [x, y]
4448 */
4549export function composeTransform ( f , g ) {
@@ -50,11 +54,12 @@ export function composeTransform(f, g) {
5054 * Return a function that memoizes the last result. If the arguments are the same as the last call,
5155 * then memoized result returned.
5256 *
53- * @param {function } f the transformation function to memoize, assumes takes two arguments 'x' and 'y'
57+ * @param {CallbackType } f the transformation function to memoize, assumes takes two arguments 'x' and 'y'
5458 *
55- * @returns {function } a function which takes x and y arguments, and will either return the saved result
59+ * @returns {CallbackType } a function which takes x and y arguments, and will either return the saved result
5660 * if the arguments are the same on subsequent calls, or compute a new result if they are different.
5761 */
5862export function memoizeTransform ( f ) {
63+ // To narrow the type of the return variable, add `/** @type {[number, number] } */` above it.
5964 throw new Error ( 'Remove this line and implement the function' ) ;
6065}
0 commit comments