Skip to content

Commit c652f05

Browse files
committed
2 parents c1c5898 + c364c4d commit c652f05

File tree

4 files changed

+85
-5
lines changed

4 files changed

+85
-5
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<<<<<<< HEAD
12
function findMinValue(arr) {
23
if (arr.length === 0) {
34
return undefined; // Handle the case where the array is empty
@@ -8,6 +9,18 @@ function findMinValue(arr) {
89
for (let i = 1; i < arr.length; i++) {
910
if (arr[i] < minValue) {
1011
minValue = arr[i]; // Update minValue if a smaller element is found
12+
=======
13+
function findMinimumValue(arr) {
14+
if (arr.length === 0) {
15+
return undefined; // Handle the case of an empty array
16+
}
17+
18+
let minValue = arr[0]; // Initialize minValue with the first element of the array
19+
20+
for (let i = 1; i < arr.length; i++) {
21+
if (arr[i] < minValue) {
22+
minValue = arr[i]; // Update minValue if a smaller value is found
23+
>>>>>>> c364c4d66ab18565041830a5a1e3e9d2de987ad1
1124
}
1225
}
1326

@@ -20,5 +33,11 @@ function findMinValue(arr) {
2033
let nums3 = [200, 5, 4, 10, 8, 5, -3.3, 4.4, 0];
2134

2235
// Using one of the test arrays as the argument, call your function inside the console.log statement below.
36+
<<<<<<< HEAD
2337
console.log(findMinValue(nums1));
24-
38+
39+
=======
40+
41+
console.log(findMinimumValue(nums1));
42+
43+
>>>>>>> c364c4d66ab18565041830a5a1e3e9d2de987ad1

more-on-functions/studio/part-three-number-sorting-easy-way.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
<<<<<<< HEAD
2+
=======
3+
// Sample arrays for testing:
4+
>>>>>>> c364c4d66ab18565041830a5a1e3e9d2de987ad1
15
let nums1 = [5, 10, 2, 42];
26
let nums2 = [-2, 0, -10, -44, 5, 3, 0, 3];
37
let nums3 = [200, 5, 4, 10, 8, 5, -3.3, 4.4, 0];
48

9+
<<<<<<< HEAD
510
nums1.sort((a, b) => a - b);
611
nums2.sort((a, b) => a - b);
712
nums3.sort((a, b) => a - b);
@@ -19,3 +24,25 @@ console.log("Sorted in descending order:");
1924
console.log(nums1);
2025
console.log(nums2);
2126
console.log(nums3);
27+
=======
28+
// Sort each array in ascending order
29+
nums1.sort((a, b) => a - b);
30+
nums2.sort((a, b) => a - b);
31+
nums3.sort((a, b) => a - b);
32+
33+
console.log("Ascending Order:");
34+
console.log("nums1:", nums1);
35+
console.log("nums2:", nums2);
36+
console.log("nums3:", nums3);
37+
38+
// Sort each array in descending order
39+
nums1.sort((a, b) => b - a);
40+
nums2.sort((a, b) => b - a);
41+
nums3.sort((a, b) => b - a);
42+
43+
console.log("\nDescending Order:");
44+
console.log("nums1:", nums1);
45+
console.log("nums2:", nums2);
46+
console.log("nums3:", nums3);
47+
48+
>>>>>>> c364c4d66ab18565041830a5a1e3e9d2de987ad1

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,37 @@ function findMinValue(arr) {
88
return min;
99
}
1010

11+
<<<<<<< HEAD
1112
function sortArray(arr) {
1213
let sortedArray = [];
1314

1415
while (arr.length > 0) {
1516
let minValue = findMinValue(arr);
17+
=======
18+
function sortArrayAscending(arr) {
19+
const sortedArray = [];
20+
21+
while (arr.length > 0) {
22+
const minValue = findMinValue(arr);
23+
>>>>>>> c364c4d66ab18565041830a5a1e3e9d2de987ad1
1624
sortedArray.push(minValue);
1725
arr.splice(arr.indexOf(minValue), 1);
1826
}
1927

2028
return sortedArray;
2129
}
2230

31+
<<<<<<< HEAD
32+
=======
33+
// Sample arrays for testing:
34+
>>>>>>> c364c4d66ab18565041830a5a1e3e9d2de987ad1
2335
let nums1 = [5, 10, 2, 42];
36+
2437
let nums2 = [-2, 0, -10, -44, 5, 3, 0, 3];
38+
2539
let nums3 = [200, 5, 4, 10, 8, 5, -3.3, 4.4, 0];
2640

41+
<<<<<<< HEAD
2742
console.log("Sorted nums1:", sortArray(nums1));
2843
console.log("Sorted nums2:", sortArray(nums2));
2944
console.log("Sorted nums3:", sortArray(nums3));
@@ -54,3 +69,11 @@ function sortArray(arr) {
5469
console.log("Sorted nums1:", sortArray(nums1));
5570
console.log("Sorted nums2:", sortArray(nums2));
5671
console.log("Sorted nums3:", sortArray(nums3));
72+
=======
73+
// Testing the sortArrayAscending function
74+
console.log(sortArrayAscending(nums1));
75+
76+
console.log(sortArrayAscending(nums2));
77+
78+
console.log(sortArrayAscending(nums3));
79+
>>>>>>> c364c4d66ab18565041830a5a1e3e9d2de987ad1

objects-and-math/exercises/ObjectExercises.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,21 @@ let salamander = {
1313
};
1414

1515

16-
// After you have created the other object literals, add the astronautID property to each one.
16+
superChimpOne.astronautID = "CHAD001";
17+
salamander.astronautID = "LACEY002";
1718

18-
// Create an array to hold the animal objects.
1919

20-
// Print out the relevant information about each animal.
20+
let animalArray = [superChimpOne, salamander];
2121

22-
// Start an animal race!
22+
23+
animalArray.forEach(animal => {
24+
console.log(`Name: ${animal.name}`);
25+
console.log(`Species: ${animal.species}`);
26+
console.log(`Mass: ${animal.mass} kg`);
27+
console.log(`Age: ${animal.age} years`);
28+
console.log(`Astronaut ID: ${animal.astronautID}`);
29+
console.log("------------");
30+
});
31+
32+
33+
console.log("The animal race is about to begin!");

0 commit comments

Comments
 (0)