Skip to content

Instantly share code, notes, and snippets.

View dandresfg's full-sized avatar
:octocat:
Hacking

Diego Andrés dandresfg

:octocat:
Hacking
View GitHub Profile
@dandresfg
dandresfg / quickSort.js
Created December 5, 2020 05:14
This is my implementation of quicksort.
function quickSort(arr){
const size = arr.length;
if(size === 0) return [];
else {
let pivot = arr[0];
let left = [];
let right = [];
for(let i = 1; i<size;i++){
@dandresfg
dandresfg / mergeSort.js
Created December 5, 2020 05:55
This is my implementation of mergesort.
function merge(left, right){
const list = [];
while(left.length && right.length){
if(left[0] < right[0]){
list.push(left[0])
left.shift();
} else {
list.push(right[0])
right.shift();
}
@dandresfg
dandresfg / countingSort.js
Created December 6, 2020 02:11
This is my implementation of countingsort.
function countingSort(arr){
const aux = Array.from({length: Math.max(...arr)+1}, (v)=> 0)
for(let i = 0; i<arr.length; i++){
aux[arr[i]] = ++aux[arr[i]];
}
for (let i = 1; i < aux.length; i++) {
let prev = aux[i-1];
let next = prev + aux[i];
aux[i] = next;
}