{"id":17142932,"url":"https://github.com/js-choi/proposal-math-between","last_synced_at":"2026-01-19T05:33:06.178Z","repository":{"id":44721250,"uuid":"512230231","full_name":"js-choi/proposal-math-between","owner":"js-choi","description":"Draft specification for a number-interval predicate in JavaScript.","archived":false,"fork":false,"pushed_at":"2022-07-12T05:14:56.000Z","size":59,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-02-12T09:57:56.952Z","etag":null,"topics":["between","interval","javascript","math","monotonic","tc39"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/js-choi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-09T16:14:23.000Z","updated_at":"2023-03-04T04:05:30.000Z","dependencies_parsed_at":"2022-09-05T12:30:20.069Z","dependency_job_id":null,"html_url":"https://github.com/js-choi/proposal-math-between","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/js-choi%2Fproposal-math-between","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/js-choi%2Fproposal-math-between/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/js-choi%2Fproposal-math-between/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/js-choi%2Fproposal-math-between/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/js-choi","download_url":"https://codeload.github.com/js-choi/proposal-math-between/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247430838,"owners_count":20937873,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["between","interval","javascript","math","monotonic","tc39"],"created_at":"2024-10-14T20:33:14.037Z","updated_at":"2026-01-19T05:33:06.172Z","avatar_url":"https://github.com/js-choi.png","language":"HTML","readme":"# Number-Interval Predicate for JavaScript\nECMAScript Stage-0 Proposal. J. S. Choi, 2021.\n\n## Description\n\nChecking whether one number is between two others is a frequent task in any\nprogramming language. However, JavaScript’s comparison operators only supports\nchecking the order between two values at a time, resulting in code that looks\nlike `x \u003c= y \u0026\u0026 y \u003c z`. A function that allows checking whether `y` is in\nbetween `x` and `z` would be useful for many developers.\n\nWe therefore propose exploring the addition of a number-interval predicate to\nthe JavaScript language. If this proposal is approved for Stage 1, then we\nwould explore various directions for the API’s design. We would also assemble\nas many real-world use cases as possible and shape our design to fulfill them.\n\n## Description\nThere are several possible ways to do this, all of which would be static\nfunctions on the Math constructor.\n\n### Option A: isIncreasing\nWe could have a variadic function checking for ascending monotonicity, with\ninclusive limits:\n```js\n// 0 ≤ 2 ≤ 3 ≤ 6:\nMath.isIncreasing(0, 2, 3, 6);\n```\n\n…or the same, except with exclusive limits:\n```js\n// 0 \u003c 2 \u003c 3 \u003c 6:\nMath.isIncreasing(0, 2, 3, 6);\n```\n\n…or with an extra boolean argument for configuration:\n```js\n// 0 ≤ 2 ≤ 3 ≤ 6:\nMath.isIncreasing([ 0, 2, 3, 6 ], true);\n// 0 \u003c 2 \u003c 3 \u003c 6:\nMath.isIncreasing([ 0, 2, 3, 6 ], false);\n```\n\n…or we could separate inclusive and exclusive limits into separate functions:\n```js\n// 0 ≤ 2 ≤ 3 ≤ 6:\nMath.isIncreasing(0, 2, 3, 6);\n// 0 \u003c 2 \u003c 3 \u003c 6:\nMath.isStrictlyIncreasing(0, 2, 3, 6);\n```\n\n### Option B: isBetween\nWe could have a function that *always* uses an inclusive minimum and exclusive\nmaximum:\n```js\n// 0 ≤ 2 \u003c 6:\nMath.isBetween(2, 0, 6);\n```\n\n…or the same except it would always use an inclusive minimum and inclusive\nmaximum:\n```js\n// 0 ≤ 2 ≤ 6:\nMath.isBetween(2, 0, 6);\n```\n\nWe could have a function that also takes two boolean arguments indicating their\nrespective limits’ inclusivity, like [Google Sheets’ `ISBETWEEN`][]:\n```js\n// 0 ≤ 2 \u003c 6:\nMath.isBetween(2, 0, 6, true, false);\n// 0 ≤ 2 ≤ 6:\nMath.isBetween(2, 0, 6, true, true);\n// 0 \u003c 2 \u003c 6:\nMath.isBetween(2, 0, 6, false, false);\n// 0 \u003c 2 ≤ 6:\nMath.isBetween(2, 0, 6, false, true);\n```\n\n(The boolean arguments might be required, or they might be optional with\ntheir default values being both true, or false and true, or something else.\n\n[Google Sheets’ `ISBETWEEN`]: https://support.google.com/docs/answer/10538337?hl=en\n\nOr we could have four functions that correspond to the four possible\nconfigurations of inclusivity, forcing the user to be explicit:\n```js\n// 0 ≤ 2 \u003c 6:\nMath.isBetweenIE(2, 0, 6);\n// 0 ≤ 2 ≤ 6:\nMath.isBetweenII(2, 0, 6);\n// 0 \u003c 2 \u003c 6:\nMath.isBetweenEE(2, 0, 6);\n// 0 \u003c 2 ≤ 6:\nMath.isBetweenEI(2, 0, 6);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjs-choi%2Fproposal-math-between","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjs-choi%2Fproposal-math-between","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjs-choi%2Fproposal-math-between/lists"}