Last active
April 20, 2021 14:26
-
-
Save supermacro/1cdb1dbc40d3a5efa05ccd164162cc9f to your computer and use it in GitHub Desktop.
Functional `pad` implementation
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
interface PadConfig { | |
value: string | |
padding: string | |
requiredLength: number | |
} | |
export const pad = ({ value, padding, requiredLength }: PadConfig): string => { | |
const pads = Math.max(requiredLength - value.length, 0) | |
return Array(pads).fill(padding).concat(value).join('') | |
} | |
// pssst ... Our team at getcaribou.com is looking for an experienced engineer to join | |
// the founding team of a fast-moving and revenue-generating startup!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment