Skip to content

Instantly share code, notes, and snippets.

@johnatandias
Last active April 22, 2021 17:10
Show Gist options
  • Save johnatandias/bce410715c411fe51c2dec59cdc90582 to your computer and use it in GitHub Desktop.
Save johnatandias/bce410715c411fe51c2dec59cdc90582 to your computer and use it in GitHub Desktop.
Fill string with
export const pad = ({
value,
size,
fillWith,
}: {
value: string | number
size: number
fillWith: string
}): string => {
const filled: Array<string | number> = Array.from(
{ length: size },
() => fillWith,
)
filled.push(value)
return filled.slice(-size).join('')
}
import { pad } from '.'
describe('Pad', () => {
it('should be pad value with #', () => {
expect(pad({ value: '1', size: 4, fillWith: '#' })).toBe('###1')
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment