{"ScriptPreparationCode":"var a=Array.from({length:100},()=\u003EMath.random())\r\n\r\nfunction insertionSort(arr){\r\n //Start from the second element.\r\n for(let i = 1; i \u003C arr.length;i\u002B\u002B){\r\n\r\n //Go through the elements behind it.\r\n for(let j = i - 1; j \u003E -1; j--){\r\n \r\n //value comparison using ascending order.\r\n if(arr[j \u002B 1] \u003C arr[j]){\r\n\r\n //swap\r\n [arr[j\u002B1],arr[j]] = [arr[j],arr[j \u002B 1]];\r\n\r\n }\r\n }\r\n };\r\n\r\n return arr;\r\n}\r\n\r\nfunction selectionSort(arr) {\r\n let min;\r\n\r\n //start passes.\r\n for (let i = 0; i \u003C arr.length; i\u002B\u002B) {\r\n //index of the smallest element to be the ith element.\r\n min = i;\r\n\r\n //Check through the rest of the array for a lesser element\r\n for (let j = i \u002B 1; j \u003C arr.length; j\u002B\u002B) {\r\n if (arr[j] \u003C arr[min]) {\r\n min = j;\r\n }\r\n }\r\n\r\n //compare the indexes\r\n if (min !== i) {\r\n //swap\r\n [arr[i], arr[min]] = [arr[min], arr[i]];\r\n }\r\n }\r\n\r\n return arr;\r\n}","TestCases":[{"Name":"sort","Code":"var b = a.slice();\r\nb.sort();","IsDeferred":false},{"Name":"insertion sort","Code":"var b = a.slice();\r\ninsertionSort(b)","IsDeferred":false},{"Name":"select sort","Code":"var b = a.slice();\r\nselectionSort(b)","IsDeferred":false}]}