Repository: npm/node-semver (JavaScript)

Issue:
[BUG] semver.diff returns incorrect responses
# What / Why

```js
const semver = require('semver');

let releaseArray = ['prepatch', 'prerelease', 'patch', 'preminor', 'prerelease', 'minor', 'premajor', 'prerelease', 'major'];
let v = '0.0.1';

releaseArray.forEach((release) => {
    let bump = semver.inc(v, release)
    let diff = semver.diff(v, bump)

    console.log(`before: '${v}'`, `after: '${bump}'`, `release type: '${release}'`, `diff response: '${diff}'`, `is diff response equal? '${release === diff}'`);
    v = bump;
});
```
console log output: (with spaces added for readability)
```
before: '0.0.1'    after: '0.0.2-0'     release type: 'prepatch'   diff response: 'prepatch'   is diff response equal? 'true'
before: '0.0.2-0'  after: '0.0.2-1'     release type: 'prerelease' diff response: 'prerelease' is diff response equal? 'true'
before: '0.0.2-1'  after: '0.0.2'       release type: 'patch'      diff response: 'prerelease' is diff response equal? 'false'
before: '0.0.2'    after: '0.1.0-0'     release type: 'preminor'   diff response: 'preminor'   is diff response equal? 'true'
before: '0.1.0-0'  after: '0.1.0-1'     release type: 'prerelease' diff response: 'prerelease' is diff response equal? 'true'
before: '0.1.0-1'  after: '0.1.0'       release type: 'minor'      diff response: 'prerelease' is diff response equal? 'false'
before: '0.1.0'    after: '1.0.0-0'     release type: 'premajor'   diff response: 'premajor'   is diff response equal? 'true'
before: '1.0.0-0'  after: '1.0.0-1'     release type: 'prerelease' diff response: 'prerelease' is diff response equal? 'true'
before: '1.0.0-1'  after: '1.0.0'       release type: 'major'      diff response: 'prerelease' is diff response equal? 'false'
```

## When
When I do go from a prerelease to a release (patch, minor, or major) semver.diff returns incorrect responses.

## Where
semver.diff

## How
semver.diff('0.0.2-1', '0.0.2')

### Current Behavior
semver.diff('0.0.2-1', '0.0.2') === 'prerelease'
semver.diff('0.1.0-1', '0.1.0') === 'prerelease'
semver.diff('1.0.0-1', '1.0.0') === 'prerelease'

### Steps to Reproduce
semver.diff('0.0.2-1', '0.0.2')

### Expected Behavior
semver.diff('0.0.2-1', '0.0.2') === 'patch'
semver.diff('0.1.0-1', '0.1.0') === 'minor'
semver.diff('1.0.0-1', '1.0.0') === 'major'

## Who
@deefactorial

## References
#288 



Fix (patch):
diff --git a/functions/diff.js b/functions/diff.js
index 651a3018..ce9004bd 100644
--- a/functions/diff.js
+++ b/functions/diff.js
@@ -10,11 +10,27 @@ const diff = (version1, version2) => {
     const hasPre = v1.prerelease.length || v2.prerelease.length
     const prefix = hasPre ? 'pre' : ''
     const defaultResult = hasPre ? 'prerelease' : ''
-    for (const key in v1) {
-      if (key === 'major' || key === 'minor' || key === 'patch') {
-        if (v1[key] !== v2[key]) {
-          return prefix + key
-        }
+
+    if (v1.major !== v2.major) {
+      return prefix + 'major'
+    }
+    if (v1.minor !== v2.minor) {
+      return prefix + 'minor'
+    }
+
+    if (v1.patch !== v2.patch) {
+      return prefix + 'patch'
+    }
+
+    if (!v1.prerelease.length || !v2.prerelease.length) {
+      if (v1.patch) {
+        return 'patch'
+      }
+      if (v1.minor) {
+        return 'minor'
+      }
+      if (v1.major) {
+        return 'major'
       }
     }
     return defaultResult // may be undefined