From c7f4950ace185cb50037f24117bcd147f85fcae3 Mon Sep 17 00:00:00 2001 From: Roshan Kumar <58213083+Roshaen@users.noreply.github.com> Date: Thu, 28 Jan 2021 21:44:53 +0530 Subject: [PATCH] Added insertion sort algorithm in js and updated README (#37) * Added insertion sort algorithm in javascript * listed sorting algorithm in javascript in README.md --- sorting/README.md | 2 ++ sorting/js/insertion-sort.js | 13 +++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 sorting/js/insertion-sort.js diff --git a/sorting/README.md b/sorting/README.md index 788b2f35..0e371b0c 100644 --- a/sorting/README.md +++ b/sorting/README.md @@ -26,4 +26,6 @@ ### JavaScript 1. [Bubble Sort](js/bubble-sort.js) +2. [Insertion Sort](js/insertion-sort.js) +3. [Selection Sort](js/selection-sort.js) diff --git a/sorting/js/insertion-sort.js b/sorting/js/insertion-sort.js new file mode 100644 index 00000000..a34beff6 --- /dev/null +++ b/sorting/js/insertion-sort.js @@ -0,0 +1,13 @@ +let sort = [12,6,3,88,1,4,8]; + +for(let i = 0; i=0){ + sort[j+1]=sort[j]; + j--; + } + sort[j+1]=key; +} +console.log(sort) \ No newline at end of file