157. semver compare

JavaScript
Is this helpful ?

easy  - accepted / - tried

Please implement a function to compare 2 semver strings.

compare('12.1.0', '12.0.9')
// 1, meaning first one is greater

compare('12.1.0', '12.1.2')
// -1, meaning latter one is greater

compare('5.0.1', '5.0.1')
// 0, meaning they are equal.

Let's try to solve this problem within 10 mintues.

Discuss(22)