Skip to content

Instantly share code, notes, and snippets.

View kevinjie's full-sized avatar
🎯
Focusing

kevinjie kevinjie

🎯
Focusing
  • Nanjing Jiangsu China
View GitHub Profile
@kevinjie
kevinjie / shellSort.js
Created January 27, 2022 02:35
shellSort
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
@kevinjie
kevinjie / countingSort.js
Created January 27, 2022 02:26
countingSort
function sort(originalArray) {
const array = [...originalArray]
let biggestElement = array[0]
let smallestElement = array[0]
array.forEach((element) => {
if (element > biggestElement) {
biggestElement = element
}
@kevinjie
kevinjie / quickSort.js
Created January 27, 2022 02:12
quickSort
export default function sort(originalArray) {
const array = [...originalArray]
if (array.length <= 1) {
return array
}
const pivot = array.shift()
const centerArray = [pivot]
@kevinjie
kevinjie / mergeSort.js
Created January 27, 2022 01:59
mergeSort
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)
@kevinjie
kevinjie / insertionSort.js
Created January 25, 2022 02:21
insertionSort
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]
) {
@kevinjie
kevinjie / selectionSort.js
Last active January 25, 2022 02:09
selectionSort
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
}
@kevinjie
kevinjie / bubbleSort.js
Last active January 25, 2022 02:09
bubbleSort
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]) {
@kevinjie
kevinjie / time.js
Created April 8, 2020 02:05
[TIME_HANDLER] 时间处理方法 #TIME
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()
@kevinjie
kevinjie / http_status.js
Created April 8, 2020 01:41
[HTTP_STATUS] 常见HTTP状态 #HTTP
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,