From a7e25afe706aae27449d06eaf2ffc3e4432fe1a0 Mon Sep 17 00:00:00 2001 From: Aymen Sakouhi <37510225+AymenSakouhi@users.noreply.github.com> Date: Thu, 19 Jan 2023 14:52:16 +0100 Subject: [PATCH] Update Selection_Sort.md --- algoexpert.io/questions/Selection_Sort.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/algoexpert.io/questions/Selection_Sort.md b/algoexpert.io/questions/Selection_Sort.md index a513eba..31ea3ef 100755 --- a/algoexpert.io/questions/Selection_Sort.md +++ b/algoexpert.io/questions/Selection_Sort.md @@ -20,3 +20,24 @@ We can use a Stack here Check this [Python](../python/Selection_Sort.py) code. +JAVASCRIPT +``` +function selectionSort(array) { + // Write your code here. + const NewArr = []; + + do { + let result = array.reduce((prev, curr) => { + return prev < curr ? prev : curr + }) + console.log(result) + let itemIndex = array.indexOf(result); + console.log(itemIndex) + NewArr.push(result) + array.splice(itemIndex, 1); + } while (array.length > 0) + + + return NewArr +} +```