-
-
Save codecademydev/f662de6d60701a0d1172b6e5149e7fbc to your computer and use it in GitHub Desktop.
Codecademy export
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
const _ = { | |
clamp(number, low, up) { | |
var bigLow = Math.max(number, low); | |
var bigUp = Math.min(bigLow, up); | |
return bigUp; | |
}, | |
inRange(number, start, end) { | |
if(end === undefined) { | |
end = start; | |
start = 0; | |
} | |
if (start > end) { | |
var temp = end; | |
end = start; | |
start = temp; | |
} | |
if (number >= start && number < end) { | |
return true | |
} else { | |
return false | |
} | |
}, | |
words(word){ | |
return word.split(" ") | |
}, | |
pad(string, length){ | |
var paddle = " "; | |
var padding = (Math.floor((length - string.length)/2)); | |
var newWord = `${paddle.repeat(padding)}${string}${paddle.repeat(padding)}`; | |
if (string.length >= length){ | |
return string | |
} else if ((length - string.length)%2 == 0) { | |
return newWord; | |
} else { | |
return newWord + paddle; | |
} | |
} | |
} | |
// Do not write or modify code below this line. | |
module.exports = _; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment