Skip to content

Instantly share code, notes, and snippets.

View mdmen's full-sized avatar

Dmitry Menov mdmen

View GitHub Profile
@mdmen
mdmen / README.md
Last active October 4, 2023 16:25
Setup MongoDB using Docker Compose as single instance (node) replica set

Don't use in production!!! For development purpose only

  1. Create compose.yml file with the following content:
services:
  mongodb:
    image: mongo
    container_name: mongodb
    volumes:
      - mongodb:/data/db
@mdmen
mdmen / insertionSort.js
Created April 16, 2018 18:00
Insertion sort is ES6
/**
* 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 April 16, 2018 17:23
Bubble sort in ES6
/**
* 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 March 18, 2018 16:18
Quick sort in ES6
/**
* 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 March 17, 2018 18:11
Selection sort in ES6
/**
* 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 March 17, 2018 18:02
Binary search in ES6
/**
* 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;