Last active
December 17, 2016 15:43
-
-
Save lopezjurip/dd3452d1232129e039f2f753e63b5a4b to your computer and use it in GitHub Desktop.
Detect semver release
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const assert = require('assert'); | |
function version(semver) { | |
const indexes = [ | |
'major', | |
'minor', | |
'patch', | |
]; | |
return semver.split('.').reduce((classification, number, index) => { | |
return (number !== '0') ? indexes[index] : classification; | |
}, indexes[0]); | |
} | |
assert(version('1.2.0') === 'minor'); | |
assert(version('2.0.0') === 'major'); | |
assert(version('2.0.2') === 'patch'); | |
assert(version('0.0.2') === 'patch'); | |
// All pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment