Created
March 30, 2016 01:16
-
-
Save zhangchiqing/0f9acb96f8073fd6abffe1c78e9b9792 to your computer and use it in GitHub Desktop.
leftPad.js
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
'use strict'; | |
var R = require('ramda'); | |
// leftPad :: Number -> String -> String | |
// > leftPad(3, '0', '7') | |
// '007' | |
// > leftPad(3, '0', '2016') | |
// '2016' | |
var leftPad = R.curry(function(num, fill, str) { | |
var repeat = R.max(0, num - str.length); | |
return R.join('', R.repeat(fill, repeat)) + str; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment