Skip to content

Commit 24c7646

Browse files
committed
Pt1 Studio-MinimumValue
1 parent 9708bf2 commit 24c7646

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,15 @@ let nums2 = [-2, 0, -10, -44, 5, 3, 0, 3];
66
let nums3 = [200, 5, 4, 10, 8, 5, -3.3, 4.4, 0];
77

88
//Using one of the test arrays as the argument, call your function inside the console.log statement below.
9+
// function minVal(arr){
910

10-
console.log(/* your code here */);
11+
function minArr(arr) {
12+
let newArr = arr[0]
13+
14+
for (let i = 1; i < arr.length; i++) {
15+
if (arr[i] < newArr) {
16+
newArr = arr[i];
17+
}
18+
}
19+
return newArr
20+
} console.log(minArr(nums1))

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,19 @@ function findMinValue(arr){
99
}
1010

1111
//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+
// function sortArr(arr) {
13+
// let arry1 = []
14+
// let arry2 = []
15+
// while (arr.length > 0) {
16+
// arry2 = findMinValue(arr)
17+
// arry1.push(arry2)
18+
// arr.splice(arr.indexOf(arry2), 1)
1219

20+
// }
21+
// return arry1
22+
23+
// }
24+
// console.log(sortArr(arr))
1325
/*Within the function:
1426
1) Define a new, empty array to hold the final sorted numbers.
1527
2) Use the findMinValue function to find the minimum value in the old array.

0 commit comments

Comments
 (0)