Skip to content

Commit 4393d2e

Browse files
more functions studio
1 parent 35ae652 commit 4393d2e

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

more-on-functions/studio/part-one-find-minimum-value.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
//1) Create a function with an array of numbers as its parameter. The function should iterate through the array and return the minimum value from the array. Hint: Use what you know about if statements to identify and store the smallest value within the array.
2+
function minimumValue(arr){
3+
let minimumValue = arr[0]
4+
for(let i = arr; i , arr.length; i++)
5+
if (arr[i] < min){
6+
}
7+
return min
8+
}
29

310
//Sample arrays for testing:
411
let nums1 = [5, 10, 2, 42];

more-on-functions/studio/part-two-create-sorted-array.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,24 @@ function findMinValue(arr){
1919
6) Be sure to print the results in order to verify your code.*/
2020

2121
//Your function here...
22-
22+
function sortArray(unsortedArray){
23+
let newArray = []
24+
for(let i =; i < unsortedArray.length; i++);{
25+
let smallest = findMinValue(unsortedArray);
26+
newArray.push(smallest)
27+
unsortedArray.splice(unsortedArray.indexOf(smallest,1))
28+
}
29+
return newArray
30+
}
2331
/* BONUS MISSION: Refactor your sorting function to use recursion below:
2432
*/
2533

34+
35+
36+
37+
function recursiveSort(unsortedArray
38+
if(unsotedArray.length == 1))
39+
2640
//Sample arrays for testing:
2741
let nums1 = [5, 10, 2, 42];
2842
let nums2 = [-2, 0, -10, -44, 5, 3, 0, 3];

0 commit comments

Comments
 (0)