- Buttons
- Matrices
- Объединенные Юристы - тестовое задание
- Mouse cursor trail
- Bouncing ball on a canvas
- Conway's Game of Life
- Deutsche Bank's Java School
- Interview Algorithm Questions in Javascript (my solutions to https://github.com/kennymkchan/interview-questions-in-javascript)
compose()
andcomposeMany()
curry()
- Term frequency (my solution to https://github.com/crista/exercises-in-programming-style)
- Proxy
Last active
May 17, 2020 09:07
-
-
Save EvgenyOrekhov/9d5ce3cded4b7c4f66cd to your computer and use it in GitHub Desktop.
JavaScript test tasks
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 bubbleSort(array) { | |
"use strict"; | |
function compareAndSwap(item, index) { | |
const nextItem = array[index + 1]; | |
if (item > nextItem) { | |
array[index + 1] = item; | |
array[index] = nextItem; | |
} | |
} | |
array.forEach(() => array.forEach(compareAndSwap)); | |
return array; | |
} | |
function combSort(array) { | |
"use strict"; | |
let gap = array.length; | |
const shrinkFactor = 1.3; | |
function compareAndSwap(item, index) { | |
const nextItem = array[index + gap]; | |
if (item > nextItem) { | |
array[index + gap] = item; | |
array[index] = nextItem; | |
} | |
return index + 1 + gap < array.length; | |
} | |
array.every(function () { | |
gap = Math.floor(gap / shrinkFactor) || 1; | |
array.every(compareAndSwap); | |
return gap > 1; | |
}); | |
return array; | |
} | |
function quicksort([pivot, ...rest]) { | |
return pivot === undefined | |
? rest | |
: [ | |
...quicksort(rest.filter((item) => item <= pivot)), | |
pivot, | |
...quicksort(rest.filter((item) => item > pivot)) | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment