Last active
April 22, 2021 17:10
-
-
Save johnatandias/bce410715c411fe51c2dec59cdc90582 to your computer and use it in GitHub Desktop.
Fill string with
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
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('') | |
} |
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
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