Created
January 13, 2026 02:38
-
-
Save davidystephenson/2a14a5a3d7fdd0df25e9a7301fa0bd64 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| export function format(value, formatter) { | |
| const formatted = formatter(value); | |
| return formatted; | |
| } | |
| function formatString (value) { | |
| return value.toUpperCase() | |
| } | |
| function formatNumber(value) { | |
| return value.toFixed(2) | |
| } | |
| const hello = format('hello', formatString); | |
| console.log(hello); // "HELLO" | |
| const pi = format(3.14159, formatNumber); | |
| console.log(pi); // "3.14" | |
| // This version should throw a type error | |
| // const invalid = format(true, formatString); | |
| // console.log(invalid); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment