Skip to content

Instantly share code, notes, and snippets.

:octocat:
Nothing to say right now

Dmitry Menov mdmen

:octocat:
Nothing to say right now
  • Moscow
Block or report user

Report or block mdmen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mdmen
mdmen / insertionSort.js
Created Apr 16, 2018
Insertion sort is ES6
View insertionSort.js
/**
* Insertion sort
* @param {array} arr - Array of numbers
*/
const insertionSort = (arr = []) => {
const length = arr.length;
for (let i = 1; i < length; i++) {
const item = arr[i];
let j = i - 1;
@mdmen
mdmen / bubbleSort.js
Last active Apr 16, 2018
Bubble sort in ES6
View bubbleSort.js
/**
* Bubble sort
* @param {array} arr - Array of numbers
*/
const bubbleSort = (arr = []) => {
const length = arr.length;
for (let i = 0; i < length; i++) {
for (let j = 0; j < length - i; j++) {
const tmp = arr[j + 1];
@mdmen
mdmen / quickSort.js
Created Mar 18, 2018
Quick sort in ES6
View quickSort.js
/**
* Quick sort
* @param {array} list - Array of numbers
* @returns {array} - Sorted array
*/
const quickSort = (list) => {
if (list.length < 2) {
return list;
}
@mdmen
mdmen / selectionSort.js
Last active Mar 17, 2018
Selection sort in ES6
View selectionSort.js
/**
* Find the index of the smallest element of the array
* @param {array} list - Array of numbers
* @returns {number} - Index
*/
const findMinItemIndex = list => {
let minIndex = 0;
let minItem = list[0];
const length = list.length;
@mdmen
mdmen / binarySearch.js
Last active Mar 17, 2018
Binary search in ES6
View binarySearch.js
/**
* Binary search
* @param {array} list - Array of numbers for search
* @param {number} elem - Looking item
* @returns {number|null} - Found index or null if not found
*/
const binarySearch = (list, elem) => {
let startIndex = 0;
let lastIndex = list.length - 1;
You can’t perform that action at this time.