Created
October 8, 2024 19:47
-
-
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`.
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
/** | |
* 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