Write .pad()
This commit is contained in:
parent
76758547dc
commit
fba7363fa4
1 changed files with 15 additions and 2 deletions
17
lodash/_.js
17
lodash/_.js
|
@ -1,4 +1,4 @@
|
|||
let _ = {}
|
||||
const _ = {}
|
||||
|
||||
/* --------------------------------------------------------------- clamp ---- */
|
||||
|
||||
|
@ -13,7 +13,7 @@ _.inRange = function (num, start, end) {
|
|||
}
|
||||
|
||||
if (start > end) {
|
||||
let s = start
|
||||
const s = start
|
||||
start = end
|
||||
end = s
|
||||
}
|
||||
|
@ -25,5 +25,18 @@ _.inRange = function (num, start, end) {
|
|||
|
||||
_.words = (string) => string.split(' ')
|
||||
|
||||
/* ----------------------------------------------------------------- pad ---- */
|
||||
|
||||
_.pad = function (string, length) {
|
||||
if (string.length >= length) {
|
||||
return string
|
||||
}
|
||||
|
||||
const addToStart = Math.floor((length - string.length) / 2)
|
||||
const addToEnd = length - string.length - addToStart
|
||||
|
||||
return ' '.repeat(addToStart) + string + ' '.repeat(addToEnd)
|
||||
}
|
||||
|
||||
// Do not write or modify code below this line.
|
||||
module.exports = _
|
||||
|
|
Loading…
Reference in a new issue