Skip to content

Commit

Permalink
v2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasschmedtmann committed Nov 11, 2021
1 parent 0a217ff commit 4a64f00
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 100 deletions.
4 changes: 1 addition & 3 deletions 01-Fundamentals-Part-1/final/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ console.log(String(23), 23);
console.log('I am ' + 23 + ' years old');
console.log('23' - '10' - 3);
console.log('23' / '2');
console.log('23' > '18');
let n = '1' + 1; // '11'
n = n - 1;
Expand Down Expand Up @@ -445,7 +444,6 @@ console.log(drink2);
console.log(`I like to drink ${age >= 18 ? 'wine 🍷' : 'water 💧'}`);
*/


////////////////////////////////////
// Coding Challenge #4

Expand All @@ -467,4 +465,4 @@ GOOD LUCK 😀
const bill = 430;
const tip = bill <= 300 && bill >= 50 ? bill * 0.15 : bill * 0.2;
console.log(`The bill was ${bill}, the tip was ${tip}, and the total value ${bill + tip}`);
*/
*/
35 changes: 33 additions & 2 deletions 09-Data-Structures-Operators/final/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const restaurant = {
},
};

/*
///////////////////////////////////////
// String Methods Practice

Expand All @@ -70,7 +69,6 @@ for (const flight of flights.split('+')) {
)} ${getCode(from)} ${getCode(to)} (${time.replace(':', 'h')})`.padStart(36);
console.log(output);
}
*/

///////////////////////////////////////
// Coding Challenge #4
Expand Down Expand Up @@ -673,6 +671,39 @@ team1 < team2 && console.log('Team 1 is more likely to win');
team1 > team2 && console.log('Team 2 is more likely to win');
///////////////////////////////////////
// Logical Assignment Operators
const rest1 = {
name: 'Capri',
// numGuests: 20,
numGuests: 0,
};
const rest2 = {
name: 'La Piazza',
owner: 'Giovanni Rossi',
};
// OR assignment operator
// rest1.numGuests = rest1.numGuests || 10;
// rest2.numGuests = rest2.numGuests || 10;
// rest1.numGuests ||= 10;
// rest2.numGuests ||= 10;
// nullish assignment operator (null or undefined)
rest1.numGuests ??= 10;
rest2.numGuests ??= 10;
// AND assignment operator
// rest1.owner = rest1.owner && '<ANONYMOUS>';
// rest2.owner = rest2.owner && '<ANONYMOUS>';
rest1.owner &&= '<ANONYMOUS>';
rest2.owner &&= '<ANONYMOUS>';
console.log(rest1);
console.log(rest2);
///////////////////////////////////////
// The Nullish Coalescing Operator
restaurant.numGuests = 0;
Expand Down
32 changes: 23 additions & 9 deletions 11-Arrays-Bankist/final/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,21 @@ console.log([...arr, ...arr2]);
console.log(letters.join(' - '));
///////////////////////////////////////
// The new at Method
const arr = [23, 11, 64];
console.log(arr[0]);
console.log(arr.at(0));
// getting last array element
console.log(arr[arr.length - 1]);
console.log(arr.slice(-1)[0]);
console.log(arr.at(-1));
console.log('jonas'.at(0));
console.log('jonas'.at(-1));
///////////////////////////////////////
// Looping Arrays: forEach
const movements = [200, 450, -400, 3000, -650, -130, 70, 1300];
Expand Down Expand Up @@ -609,7 +624,7 @@ console.log(movements);
const arr = [1, 2, 3, 4, 5, 6, 7];
console.log(new Array(1, 2, 3, 4, 5, 6, 7));
// Empty arrays + fill method
// Emprty arrays + fill method
const x = new Array(7);
console.log(x);
// console.log(x.map(() => 5));
Expand All @@ -636,7 +651,7 @@ labelBalance.addEventListener('click', function () {
const movementsUI2 = [...document.querySelectorAll('.movements__value')];
});
*/

///////////////////////////////////////
// Array Methods Practice
Expand All @@ -657,10 +672,10 @@ console.log(bankDepositSum);
const numDeposits1000 = accounts
.flatMap(acc => acc.movements)
.reduce((count, cur) => (cur >= 1000 ? ++count : count), 0);

console.log(numDeposits1000);

// Prefixed ++ operator
// Prefixed ++ oeprator
let a = 10;
console.log(++a);
console.log(a);
Expand All @@ -676,29 +691,28 @@ const { deposits, withdrawals } = accounts
},
{ deposits: 0, withdrawals: 0 }
);

console.log(deposits, withdrawals);

// 4.
// this is a nice title -> This Is a Nice Title
const convertTitleCase = function (title) {
const capitalize = str => str[0].toUpperCase() + str.slice(1);
const capitzalize = str => str[0].toUpperCase() + str.slice(1);

const exceptions = ['a', 'an', 'and', 'the', 'but', 'or', 'on', 'in', 'with'];

const titleCase = title
.toLowerCase()
.split(' ')
.map(word => (exceptions.includes(word) ? word : capitalize(word)))
.map(word => (exceptions.includes(word) ? word : capitzalize(word)))
.join(' ');

return capitalize(titleCase);
return capitzalize(titleCase);
};

console.log(convertTitleCase('this is a nice title'));
console.log(convertTitleCase('this is a LONG title but not too long'));
console.log(convertTitleCase('and here is another title with an EXAMPLE'));
*/

///////////////////////////////////////
// Coding Challenge #4
Expand Down
Loading

0 comments on commit 4a64f00

Please sign in to comment.