Skip to content

Instantly share code, notes, and snippets.

@AguacateVelarde
Created August 16, 2021 18:35
Show Gist options
  • Save AguacateVelarde/bfad0cfd7d034482ab78d5650af521bf to your computer and use it in GitHub Desktop.
Save AguacateVelarde/bfad0cfd7d034482ab78d5650af521bf to your computer and use it in GitHub Desktop.
const assert = require("assert");
function sortingNumbers(list = []) {
assert(list);
let currentActiveNumber = Number.MIN_SAFE_INTEGER;
return list.reduce((accumulator, current) => {
if (currentActiveNumber < current) {
accumulator.push(current);
currentActiveNumber = current;
}
return accumulator;
}, []);
}
const firstTesting = sortingNumbers([
9, 44, 32, 12, 7, 45, 31, 98, 35, 41, 8, 20, 27, 32, 83, 64, 61, 28, 39, 93,
29, 92, 17,
]);
const firstRespose = [9, 44, 45, 98];
const secondTesting = sortingNumbers([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
const secondResponse = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const thirdTesting = sortingNumbers([]);
const thirdResponse = [];
const fourtyTesting = sortingNumbers([9, 9, 9, 9, 9, 9, 9, 9]);
const fourtyResponse = [9];
assert(firstTesting, firstRespose);
assert(secondTesting, secondResponse);
assert(thirdTesting, thirdResponse);
assert(fourtyTesting, fourtyResponse);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment