forked from LaunchCodeEducation/javascript-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
COmpleted Studio - More on functions
- Loading branch information
1 parent
37597ca
commit 700209d
Showing
3 changed files
with
37 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
//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. | ||
|
||
//Sample arrays for testing: | ||
let nums1 = [5, 10, 2, 42]; | ||
let nums2 = [-2, 0, -10, -44, 5, 3, 0, 3]; | ||
let nums3 = [200, 5, 4, 10, 8, 5, -3.3, 4.4, 0]; | ||
|
||
//Using one of the test arrays as the argument, call your function inside the console.log statement below. | ||
function findTheSmallestNumber(arr){ | ||
function getSmallestNumber(arr){ | ||
let smallestNumber = arr[0]; | ||
for (let index = 0; index < arr.length; index++) { | ||
if(arr[index] < smallestNumber){ | ||
smallestNumber = arr[index]; | ||
} | ||
console.log(smallestNumber); | ||
} | ||
return smallestNumber; | ||
} | ||
console.log(`The smalllest value in the array is ${findTheSmallestNumber(nums1)}`); | ||
}; | ||
console.log("The smallest number in the array is ", getSmallestNumber(nums3)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters