-
-
Save codecademydev/f41417190eca24d18518a156c2952d8f 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, lower, upper) { | |
const lowerClampedValue = Math.max(number, lower); | |
const clampedValue = Math.min(lowerClampedValue, upper); | |
return clampedValue; | |
}, | |
inRange(number, start, end) { | |
if(end === undefined) { | |
end = start; | |
start = 0; | |
}; | |
if(start > end) { | |
const temp = end; | |
end = start; | |
start = temp; | |
}; | |
const isInRange = start <= number && number < end; | |
return isInRange; | |
}, | |
words(string) { | |
const words = string.split(' '); | |
return words; | |
}, | |
pad(string, length) { | |
if(string.length >= length) { | |
return string; | |
}; | |
const startPaddingLength = Math.floor((length - string.length) / 2); | |
const endPaddingLength = length - string.length - startPaddingLength; | |
const paddedString = (' ').repeat(startPaddingLength) + string + (' ').repeat(endPaddingLength); | |
return paddedString; | |
}, | |
has(object, key) { | |
/*if(object[key]) { | |
return true; | |
} return false;*/ | |
const hasValue = object[key]; | |
if(hasValue === undefined) { | |
return false; | |
} return true; | |
}, | |
invert(object) { | |
let invertedObject = {}; | |
for (let key in object) { | |
const originalValue = object[key]; | |
invertedObject = {originalValue: key} | |
} | |
return invertedObject; | |
} | |
}; | |
// 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