diff --git a/04 - Array Cardio Day 1/README.md b/04 - Array Cardio Day 1/README.md new file mode 100644 index 0000000000..60ca0098a0 --- /dev/null +++ b/04 - Array Cardio Day 1/README.md @@ -0,0 +1,2 @@ +## 1.Do the 6th exercise after dom exercise +## \ No newline at end of file diff --git a/04 - Array Cardio Day 1/index-START.html b/04 - Array Cardio Day 1/index-START.html index 0dcfd00f40..6360afdd7d 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -27,7 +27,7 @@ { first: 'Lise', last: 'Meitner', year: 1878, passed: 1968 }, { first: 'Hanna', last: 'Hammarström', year: 1829, passed: 1909 } ]; - + const people = [ 'Bernhard, Sandra', 'Bethea, Erin', 'Becker, Carl', 'Bentsen, Lloyd', 'Beckett, Samuel', 'Blake, William', 'Berger, Ric', 'Beddoes, Mick', 'Beethoven, Ludwig', 'Belloc, Hilaire', 'Begin, Menachem', 'Bellow, Saul', 'Benchley, Robert', 'Blair, Robert', 'Benenson, Peter', 'Benjamin, Walter', 'Berlin, Irving', @@ -35,31 +35,52 @@ 'Berne, Eric', 'Berra, Yogi', 'Berry, Wendell', 'Bevan, Aneurin', 'Ben-Gurion, David', 'Bevel, Ken', 'Biden, Joseph', 'Bennington, Chester', 'Bierce, Ambrose', 'Billings, Josh', 'Birrell, Augustine', 'Blair, Tony', 'Beecher, Henry', 'Biondo, Frank' ]; - + // Array.prototype.filter() // 1. Filter the list of inventors for those who were born in the 1500's + const inventorsOf1500=inventors.filter((inventor)=>(inventor.year>=1500 && inventor.year<1600)); + console.table(inventorsOf1500); // Array.prototype.map() // 2. Give us an array of the inventors first and last names - + const inventorFullNames=inventors.map((inventor)=>inventor.first.concat(' ',inventor.last)); + console.log(inventorFullNames); + // Array.prototype.sort() // 3. Sort the inventors by birthdate, oldest to youngest - - // Array.prototype.reduce() + inventors.sort((a,b)=>a.year-b.year); + console.log(inventors); + // Array.prototype.reduce() // 4. How many years did all the inventors live all together? - - // 5. Sort the inventors by years lived - + const totalYear=inventors.reduce((acc,curr)=>acc+(curr.passed-curr.year),0); + console.log(totalYear); + + // 5. Sort the inventors by years lived + const oldest = inventors.sort((a,b)=>((b.passed-b.year)-(a.passed-a.year))); + console.table(oldest); // 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name // https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris // 7. sort Exercise // Sort the people alphabetically by last name - + const sortedByLastName=people.sort((a,b)=>{ + const aLastName=a.split(','); + const bLastName=b.split(','); + return aLastName[0].localeCompare(bLastName[0]); + }) + console.table(people); // 8. Reduce Exercise // Sum up the instances of each of these const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ]; + const freq=data.reduce((acc,curr)=>{ + if(!acc[curr]) + acc[curr]=1; + else + acc[curr]++; + return acc; + },{}); + console.table(freq); diff --git a/07 - Array Cardio Day 2/index-START.html b/07 - Array Cardio Day 2/index-START.html index 4ca34c7536..8a039f7f2f 100644 --- a/07 - Array Cardio Day 2/index-START.html +++ b/07 - Array Cardio Day 2/index-START.html @@ -26,17 +26,29 @@ ]; // Some and Every Checks + // Array.prototype.some() // is at least one person 19 or older? + const isAdult=people.some((person)=>( (new Date).getFullYear-person.year)>=19); + console.log({isAdult}); + // Array.prototype.every() // is everyone 19 or older? + const areTheyAdult=people.every((person)=>( (new Date).getFullYear-person.year)>=19); + console.log({areTheyAdult}); // Array.prototype.find() // Find is like filter, but instead returns just the one you are looking for // find the comment with the ID of 823423 - + const idFinder=comments.find((person)=>person.id===823423); + console.log(idFinder); // Array.prototype.findIndex() // Find the comment with this ID + const idIndexFinder=comments.findIndex((person)=>person.id===823423); + console.log(idIndexFinder); // delete the comment with the ID of 823423 - + + comments.splice(idIndexFinder,1); + console.table(comments) +