← Back to challenges

Semantic Versioning

JavaScriptHardstringsformatting

Instructions

In semantic versioning a piece of software can be represented in a format like this example: 6.1.9.

  1. The first number is the major version.
  2. The second number is the minor version.
  3. The third number is the patch (bug fixes).

Write three separate functions, one to retrieve each element in the semantic versioning specification.

Examples

// 6.1.9
retrieveMajor("6.1.9") ➞ "6"

retrieveMinor("6.1.9") ➞ "1"

retrievePatch("6.1.9") ➞ "9"

// 2.1.0
retrieveMajor("2.1.0") ➞ "2"

retrieveMinor("2.1.0") ➞ "1"

retrievePatch("2.1.0") ➞ "0"

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Multiply by Length