Skip to content

Commit

Permalink
Refactor sorting function
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptronicek committed Oct 12, 2023
1 parent 238b9a8 commit 8287c9f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions .autofix/fixers/update-lang-python.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const os = require('os');

function sortSemVer(arr, reverse = false) {
let semVerArr = arr.map(i => i.replace(/(\d+)/g, m => +m + 100000)).sort(); // +m is just a short way of converting the match to int
if (reverse)
semVerArr = semVerArr.reverse();
// Adapted from https://stackoverflow.com/a/71331716/10199319 (CC BY-SA 4.0)
function sortVersions(versionArray, reverse = false) {
let semVerArr = versionArray.map(i => i.replace(/(\d+)/g, m => +m + 100000)).sort(); // +m is just a short way of converting the match to int
if (reverse) {
semVerArr = semVerArr.reverse();
}

return semVerArr.map(i => i.replace(/(\d+)/g, m => +m - 100000))
}
Expand All @@ -12,7 +14,7 @@ exports.register = async (fixers) => {
const response = await fetch("https://raw.githubusercontent.com/endoflife-date/release-data/main/releases/python.json");
const data = await response.json();

const versions = sortSemVer(Object.keys(data));
const versions = sortVersions(Object.keys(data));

const patchVersionReplacements = {};
for (const version of versions) {
Expand Down

0 comments on commit 8287c9f

Please sign in to comment.