Skip to content

Instantly share code, notes, and snippets.

@westc
Created October 8, 2024 19:47
Show Gist options
  • Save westc/fc31a74fb878fe80286448123d42526c to your computer and use it in GitHub Desktop.
Save westc/fc31a74fb878fe80286448123d42526c to your computer and use it in GitHub Desktop.
getNextMultiple() — Finds the smallest multiple of `multipleOf` that is greater than or equal to `baseValue + offset`.
/**
* Finds the smallest multiple of `multipleOf` that is greater than or equal to
* `baseValue + offset`.
*
* @param {number} multipleOf
* The number whose multiple needs to be found.
* @param {number} baseValue
* The base value to start from.
* @param {number} [offset=0]
* The optional value to add to `baseValue` (default is 0).
* @returns {number}
* The smallest multiple of `multipleOf` that is greater than or equal to
* `baseValue + offset`.
*/
function getNextMultiple(multipleOf, baseValue, offset = 0) {
return Math.ceil((baseValue + offset) / multipleOf) * multipleOf;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment