Last active
February 28, 2024 07:17
-
-
Save dutchcelt/f9a0605b68fc84da4a4fe44811691851 to your computer and use it in GitHub Desktop.
Convert a step value to a corresponding T-shirt size
This file contains hidden or 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
/** | |
* Converts a step value to a corresponding T-shirt size. | |
* The default value '0' is equal to 'm'. | |
* @param {number} step - The step value to convert into a T-shirt size. | |
* @returns {string} The T-shirt size corresponding to the given step value. | |
*/ | |
const convertToTShirtSize = (step = 0) => { | |
const times = Math.max(0, Math.abs(step) - 1); | |
const index = Math.sign(step) + 1; | |
return 'x'.repeat(times) + ['s','m','l'][index]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment