January 2020
Intermediate to advanced
640 pages
16h 56m
English
If we are given two semantic versions, a.b.c and x.y.z, how can we tell which one is more recent? To compare two semantic versions, we need to compare each one of their individual components from left to right. Here is a short piece of code demonstrating how we can compare two semantic versions:
// SemVer contains the major, minor, patch components of a semantic version// string. type SemVer [3]int // GreaterThan returns true if the receiver version is greater than other. func (sv SemVer) GreaterThan(other SemVer) bool { for i, v := range sv { if v != other[i] { return v > other[i] } } return false }
Comparing or sorting semantic versions is quite an easy task for humans to perform, but nevertheless, as is evident ...