Created
October 21, 2020 19:06
-
-
Save sccolbert/98474faad53ae3011029b7c8f67bd3b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A generator function which maps a function across an iterable of values. | |
*/ | |
function map(fn, items) { // Add typings to the function definition | |
// Implement the body of the function | |
} | |
interface HasLength { | |
length: number; | |
} | |
function getLength<T extends HasLength>(thing: T): number { | |
return thing.length; | |
} | |
// Example Usage | |
for (let length of map(getLength, ['cat', 'dog', 'mouse', 'canada'])) { | |
console.log(length); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment