Skip to content

Instantly share code, notes, and snippets.

@zhangchiqing
Created March 30, 2016 01:16
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 zhangchiqing/0f9acb96f8073fd6abffe1c78e9b9792 to your computer and use it in GitHub Desktop.
Save zhangchiqing/0f9acb96f8073fd6abffe1c78e9b9792 to your computer and use it in GitHub Desktop.
leftPad.js
'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