Skip to content

Commit 2cf9110

Browse files
committed
completed studio starter code
1 parent a0ae009 commit 2cf9110

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//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+
3+
//Sample arrays for testing:
4+
let nums1 = [5, 10, 2, 42];
5+
let nums2 = [-2, 0, -10, -44, 5, 3, 0, 3];
6+
let nums3 = [200, 5, 4, 10, 8, 5, -3.3, 4.4, 0];
7+
8+
//Using one of the test arrays as the argument, call your function inside the console.log statement below.
9+
10+
console.log(/* your code here */);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//Sample arrays for testing:
2+
let nums1 = [5, 10, 2, 42];
3+
let nums2 = [-2, 0, -10, -44, 5, 3, 0, 3];
4+
let nums3 = [200, 5, 4, 10, 8, 5, -3.3, 4.4, 0];
5+
6+
//Sort each array in ascending order.
7+
8+
//Sort each array in decending order.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function findMinValue(arr){
2+
let min = arr[0];
3+
for (i = 0; i < arr.length; i++){
4+
if (arr[i] < min){
5+
min = arr[i];
6+
}
7+
}
8+
return min;
9+
}
10+
11+
//Create a function with an array of numbers as its parameter. This function will return a new array with the numbers sorted from least to greatest value.
12+
13+
/*Within the function:
14+
1) Define a new, empty array to hold the final sorted numbers.
15+
2) Use the findMinValue function to find the minimum value in the old array.
16+
3) Add the minimum value to the new array, and remove the minimum value from the old array.
17+
4) Repeat parts b & c until the old array is empty.
18+
5) Return the new sorted array.
19+
6) Be sure to print the results in order to verify your code.*/
20+
21+
//Your function here...
22+
23+
/* BONUS MISSION: Refactor your sorting function to use recursion below:
24+
*/
25+
26+
//Sample arrays for testing:
27+
let nums1 = [5, 10, 2, 42];
28+
let nums2 = [-2, 0, -10, -44, 5, 3, 0, 3];
29+
let nums3 = [200, 5, 4, 10, 8, 5, -3.3, 4.4, 0];

0 commit comments

Comments
 (0)