Skip to content

Commit 0156ffd

Browse files
v2.3 (new lectures)
1 parent 6d37155 commit 0156ffd

File tree

8 files changed

+483
-130
lines changed

8 files changed

+483
-130
lines changed

Diff for: 03-Developer-Skills/final/script.js

+67
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,70 @@ const printForecast = function (arr) {
159159
printForecast(data1);
160160
*/
161161

162+
///////////////////////////////////////
163+
// Coding Challenge #2 With AI
164+
165+
/*
166+
Let's say you're building a time tracking application for freelancers. At some point in building this app, you need a function that receives daily work hours for a certain week, and returns:
167+
1. Total hours worked
168+
2. Average daily hours
169+
3. The day with the most hours worked
170+
4. Number of days worked
171+
5. Whether the week was full-time (worked 35 hours or more)
172+
173+
TEST DATA: [7.5, 8, 6.5, 0, 8.5, 4, 0]
174+
*/
175+
176+
/*
177+
// Written by ChatGPT
178+
function analyzeWorkWeek(dailyHours) {
179+
const daysOfWeek = [
180+
'Monday',
181+
'Tuesday',
182+
'Wednesday',
183+
'Thursday',
184+
'Friday',
185+
'Saturday',
186+
'Sunday',
187+
];
188+
189+
// Validate that the input array has exactly 7 elements
190+
if (!Array.isArray(dailyHours) || dailyHours.length !== 7) {
191+
throw new Error('Input must be an array of exactly 7 daily work hours.');
192+
}
193+
194+
// Calculate total hours worked
195+
const totalHours = dailyHours.reduce((sum, hours) => sum + hours, 0);
196+
197+
// Calculate average daily hours, rounded to one decimal place
198+
const averageHours = Math.round((totalHours / dailyHours.length) * 10) / 10;
199+
200+
// Find the day with the most hours worked
201+
const maxHours = Math.max(...dailyHours);
202+
const maxDayIndex = dailyHours.indexOf(maxHours);
203+
const maxDay = daysOfWeek[maxDayIndex]; // Convert index to day name
204+
205+
// Count the number of days worked
206+
const daysWorked = dailyHours.filter(hours => hours > 0).length;
207+
208+
// Check if the week was full-time (35 hours or more)
209+
const isFullTime = totalHours >= 35;
210+
211+
// Return the result object
212+
return {
213+
totalHours,
214+
averageHours,
215+
maxDay, // The name of the day with the most hours
216+
daysWorked,
217+
isFullTime,
218+
};
219+
}
220+
221+
const weeklyHours = [7.5, 8, 6.5, 0, 8.5, 5, 0];
222+
const analysis = analyzeWorkWeek(weeklyHours);
223+
console.log(analysis);
224+
225+
const weeklyHours2 = [7.5, 8, 6.5, 0, 8.5];
226+
const analysis2 = analyzeWorkWeek(weeklyHours2);
227+
console.log(analysis2);
228+
*/

Diff for: 08-Behind-the-Scenes/final/script.js

+31-41
Original file line numberDiff line numberDiff line change
@@ -175,59 +175,49 @@ addArrow(2, 5, 8);
175175
176176
177177
///////////////////////////////////////
178-
// Objects vs. primitives
179-
let age = 30;
180-
let oldAge = age;
181-
age = 31;
182-
console.log(age);
183-
console.log(oldAge);
184-
185-
const me = {
186-
name: 'Jonas',
187-
age: 30,
178+
// Object References in Practice (Shallow vs. Deep Copies)
179+
180+
const jessica1 = {
181+
firstName: 'Jessica',
182+
lastName: 'Williams',
183+
age: 27,
188184
};
189-
const friend = me;
190-
friend.age = 27;
191-
console.log('Friend:', friend);
192-
console.log('Me', me);
193185
186+
function marryPerson(originalPerson, newLastName) {
187+
originalPerson.lastName = newLastName;
188+
return originalPerson;
189+
}
194190
195-
///////////////////////////////////////
196-
// Primitives vs. Objects in Practice
191+
const marriedJessica = marryPerson(jessica1, 'Davis');
192+
193+
// const marriedJessica = jessica1;
194+
// marriedJessica.lastName = 'Davis';
197195
198-
// Primitive types
199-
let lastName = 'Williams';
200-
let oldLastName = lastName;
201-
lastName = 'Davis';
202-
console.log(lastName, oldLastName);
196+
console.log('Before:', jessica1);
197+
console.log('After:', marriedJessica);
203198
204-
// Reference types
205199
const jessica = {
206200
firstName: 'Jessica',
207201
lastName: 'Williams',
208202
age: 27,
209-
};
210-
const marriedJessica = jessica;
211-
marriedJessica.lastName = 'Davis';
212-
console.log('Before marriage:', jessica);
213-
console.log('After marriage: ', marriedJessica);
214-
// marriedJessica = {};
215-
216-
// Copying objects
217-
const jessica2 = {
218-
firstName: 'Jessica',
219-
lastName: 'Williams',
220-
age: 27,
221-
family: ['Alice', 'Bob'],
203+
familiy: ['Alice', 'Bob'],
222204
};
223205
224-
const jessicaCopy = Object.assign({}, jessica2);
206+
// Shallow copy
207+
const jessicaCopy = { ...jessica };
225208
jessicaCopy.lastName = 'Davis';
226209
227-
jessicaCopy.family.push('Mary');
228-
jessicaCopy.family.push('John');
210+
// jessicaCopy.familiy.push('Mary');
211+
// jessicaCopy.familiy.push('John');
229212
230-
console.log('Before marriage:', jessica2);
231-
console.log('After marriage: ', jessicaCopy);
232-
*/
213+
// console.log('Before:', jessica);
214+
// console.log('After:', jessicaCopy);
215+
216+
// Deep copy/clone
217+
const jessicaClone = structuredClone(jessica);
218+
jessicaClone.familiy.push('Mary');
219+
jessicaClone.familiy.push('John');
233220
221+
console.log('Original:', jessica);
222+
console.log('Clone:', jessicaClone);
223+
*/

Diff for: 09-Data-Structures-Operators/final/script.js

+46-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const restaurant = {
4848
},
4949
};
5050

51+
/*
5152
///////////////////////////////////////
5253
// String Methods Practice
5354
@@ -73,7 +74,7 @@ for (const flight of flights.split('+')) {
7374
///////////////////////////////////////
7475
// Coding Challenge #4
7576
76-
/*
77+
7778
Write a program that receives a list of variable names written in underscore_case and convert them to camelCase.
7879
7980
The input will come from a textarea inserted into the DOM (see code below), and conversion will happen when the button is pressed.
@@ -409,6 +410,49 @@ console.log(rest.size);
409410
console.log(rest.get(arr));
410411
411412
413+
///////////////////////////////////////
414+
// New Operations to Make Sets Useful!
415+
416+
const italianFoods = new Set([
417+
'pasta',
418+
'gnocchi',
419+
'tomatoes',
420+
'olive oil',
421+
'garlic',
422+
'basil',
423+
]);
424+
425+
const mexicanFoods = new Set([
426+
'tortillas',
427+
'beans',
428+
'rice',
429+
'tomatoes',
430+
'avocado',
431+
'garlic',
432+
]);
433+
434+
const commonFoods = italianFoods.intersection(mexicanFoods);
435+
console.log('Intersection:', commonFoods);
436+
console.log([...commonFoods]);
437+
438+
const italianMexicanFusion = italianFoods.union(mexicanFoods);
439+
console.log('Union:', italianMexicanFusion);
440+
441+
console.log([...new Set([...italianFoods, ...mexicanFoods])]);
442+
443+
const uniqueItalianFoods = italianFoods.difference(mexicanFoods);
444+
console.log('Difference italian', uniqueItalianFoods);
445+
446+
const uniqueMexicanFoods = mexicanFoods.difference(italianFoods);
447+
console.log('Difference mexican', uniqueMexicanFoods);
448+
449+
const uniqueItalianAndMexicanFoods =
450+
italianFoods.symmetricDifference(mexicanFoods);
451+
console.log(uniqueItalianAndMexicanFoods);
452+
453+
console.log(italianFoods.isDisjointFrom(mexicanFoods));
454+
455+
412456
///////////////////////////////////////
413457
// Sets
414458
const ordersSet = new Set([
@@ -716,6 +760,7 @@ console.log(guests);
716760
const guestCorrect = restaurant.numGuests ?? 10;
717761
console.log(guestCorrect);
718762
763+
719764
///////////////////////////////////////
720765
// Short Circuiting (&& and ||)
721766

Diff for: 09-Data-Structures-Operators/starter/script.js

+18
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@
44
const flights =
55
'_Delayed_Departure;fao93766109;txl2133758440;11:25+_Arrival;bru0943384722;fao93766109;11:45+_Delayed_Arrival;hel7439299980;fao93766109;12:05+_Departure;fao93766109;lis2323639855;12:30';
66

7+
const italianFoods = new Set([
8+
'pasta',
9+
'gnocchi',
10+
'tomatoes',
11+
'olive oil',
12+
'garlic',
13+
'basil',
14+
]);
15+
16+
const mexicanFoods = new Set([
17+
'tortillas',
18+
'beans',
19+
'rice',
20+
'tomatoes',
21+
'avocado',
22+
'garlic',
23+
]);
24+
725
// Data needed for first part of the section
826
const restaurant = {
927
name: 'Classico Italiano',

0 commit comments

Comments
 (0)