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
export default function sort(originalArray) { | |
const array = [...originalArray] | |
let gap = Math.floor(array.length / 2) | |
while(gap > 0) { | |
for(let i = 0; i < array.length - gap; i += 1) { | |
let currentIndex = i | |
let gapShiftedIndex = i + gap |
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
function sort(originalArray) { | |
const array = [...originalArray] | |
let biggestElement = array[0] | |
let smallestElement = array[0] | |
array.forEach((element) => { | |
if (element > biggestElement) { | |
biggestElement = element | |
} |
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
export default function sort(originalArray) { | |
const array = [...originalArray] | |
if (array.length <= 1) { | |
return array | |
} | |
const pivot = array.shift() | |
const centerArray = [pivot] |
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
function sort(originalArray) { | |
const arr = [...originalArray] | |
if (arr.length <= 1) { | |
return arr | |
} | |
const middleIndex = Math.floor(arr.length / 2) | |
const leftArray = arr.slice(0, middleIndex) | |
const rightArray = arr.slice(middleIndex, arr.length) |
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
export default function sort(originalArray) { | |
const arr = [...originalArray] | |
for(let i = 1; i < arr.length; i += 1) { | |
let currentIndex = i | |
while( | |
arr[currentIndex - 1] !== undefined | |
&& arr[currentIndex - 1] > arr[currentIndex] | |
) { |
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
export default function sort(originalArray) { | |
const arr = [...originalArray] | |
for(let i = 0; i < arr.length - 1; i += 1) { | |
let minIndex = i | |
for(let j = i + 1;j < arr.length; j += 1) { | |
if (arr[minIndex] > arr[j]) { | |
minIndex = j | |
} |
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
export default function sort(originalArray) { | |
const arr = [...originalArray] | |
let N = arr.length | |
let swapped = false | |
while (N > 0) { | |
swapped = false | |
for(let j = 0; j < N - 1; j += 1) { | |
if (arr[j] > arr[j+1]) { |
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
export const formatNumber = n => { | |
n = n.toString() | |
return n[1] ? n : '0' + n | |
} | |
export const formatTime = date => { | |
const year = date.getFullYear() | |
const month = date.getMonth() + 1 | |
const day = date.getDate() | |
const hour = date.getHours() |
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
export const HTTP_STATUS = { | |
SUCCESS: 200, | |
CREATED: 201, | |
ACCEPTED: 202, | |
CLIENT_ERROR: 400, | |
AUTHENTICATE: 401, | |
FORBIDDEN: 403, | |
NOT_FOUND: 404, | |
SERVER_ERROR: 500, | |
BAD_GATEWAY: 502, |