← All Exercises
Resolve the Best Version for Constraints
intermediatejavascript
Background
Dependency upgrades go wrong when caret and tilde semantics are treated as "close enough". Resolving them explicitly is what automerge tooling relies on.
Problem
Evaluate caret, tilde, range and comparison constraints against candidate versions and return the highest satisfying version plus the satisfying set.
Input
JSON object: { constraints: string[], available: string[] }Output
JSON object: { best: string | null, satisfying: string[] }Sample tests
Sample 1
Input: {"constraints":["^1.2.0","<2.0.0"],"available":["1.1.0","1.2.5","1.9.3","2.0.0"]}Expected: {"best":"1.9.3","satisfying":["1.2.5","1.9.3"]}Sample 2
Input: {"constraints":["~1.4.0"],"available":["1.4.0","1.4.9","1.5.0"]}Expected: {"best":"1.4.9","satisfying":["1.4.0","1.4.9"]}Your solution
Learning objective
Resolve dependency constraints with explicit semver semantics.