Skip to content

Instantly share code, notes, and snippets.

@supermacro
Last active April 20, 2021 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save supermacro/1cdb1dbc40d3a5efa05ccd164162cc9f to your computer and use it in GitHub Desktop.
Save supermacro/1cdb1dbc40d3a5efa05ccd164162cc9f to your computer and use it in GitHub Desktop.
Functional `pad` implementation
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