Skip to content

Instantly share code, notes, and snippets.

@dutchcelt
Last active February 28, 2024 07:17
Show Gist options
  • Save dutchcelt/f9a0605b68fc84da4a4fe44811691851 to your computer and use it in GitHub Desktop.
Save dutchcelt/f9a0605b68fc84da4a4fe44811691851 to your computer and use it in GitHub Desktop.
Convert a step value to a corresponding T-shirt size
/**
* 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