157. semver compare

JavaScript

easy  - accepted / - tried

Please implement a function to compare 2 semver strings.

compare('12.1.0', '12.0.9')// 1, meaning first one is greatercompare('12.1.0', '12.1.2')// -1, meaning latter one is greatercompare('5.0.1', '5.0.1')// 0, meaning they are equal.

Always try to find a better approach.