Today, I’m focusing on Arrays and Objects. I’m working on a series of code problems that require me to determine whether to use .filter, .map, or other methods.
Arrays are ordered, indexed collections and are great for storing lists where the order is significant. On the other hand, Objects consist of unordered key-value pairs and are perfect for representing entities with properties. The decision to use either objects or arrays depends on the data type you’re dealing with and how you intend to manipulate or access that data. Generally, arrays are best suited for maintaining the order of elements, while objects are used when it’s necessary to label elements with keys.
I don’t know if anyone needed to know that, but now you know.
O’Malley surprised me by biting my toe from under the desk, but thankfully, he didn’t bite too hard. Chris has passed his driving test, so he can now drive. Alexis expressed interest in practicing driving at some point.
The garage door repairmen came to inspect the issue with the door. They found that a part of the door was broken, making it too heavy to open. They are scheduled to return tomorrow to replace the entire assembly. I asked Chris to handle the repairmen because I was busy studying and didn’t feel comfortable dealing with the garage door issue on my own, especially since Chris has better hearing than I do.
I’ve been regularly checking the passport status page for any updates. The status has been ‘in process’ for the past five days, and we were informed that it may take two to three weeks to complete the process. We recently discovered that our passport card cannot be used for international flights, so we urgently expedited the passport processing and opted for priority mailing. We should receive the passport booklet before our upcoming trip.
I’ve been neglecting my book discussions lately. Right now, I’m engrossed in the book Wordslut. It’s an insightful analysis of how language mirrors and perpetuates gender disparities. It’s about sexism in language. The author blends thorough research with amusing stories. It’s not a bad read, but it’s very much an entry-level exploration of feminism with a touch of sociolinguistics.
Currently, I’m using my computer tower as a footrest, and I’m hesitant to start working on the computer, even though I believe I can install the hard drive. Despite my slightly poor eyesight, I have experience with installing hard drives in the past. However, it’s an SSD drive this time, which differs from what I’ve worked on before. I miss playing games on my computer. Oh, all my mods for Skyrim are gone. It took a while to get those mods working. I never used mods in Ffxiv because it goes against the Terms of Service, and they take that seriously. I sometimes play on my Switch, but it’s different from playing on the computer. Unfortunately, my laptop isn’t designed for gaming.
JavaScript notes…
——————————
// Array.prototype.filter()
// 1. Filter the list of inventors for those who were born in the 1500’s
const bornIn1500s = inventors.filter(inventor => inventor.year >= 1500 && inventor.year // Array.prototype.map() // 2. Give us an array of the inventors first and last namesconst fullNames = inventors.map(inventor => `${inventor.first} ${inventor.last}`); console.log(fullNames);// Array.prototype.sort()
// 3. Sort the inventors by birthdate, oldest to youngest
const ordered = inventors.sort((a, b) => a.year > b.year ? 1 : -1); console.table(ordered);// Array.prototype.reduce()
// 4. How many years did all the inventors live all together?
const live = inventors.reduce((total, inventor) => { return total + (inventor.passed - inventor.year); }, 0); console.log(live);// 5. Sort the inventors by years lived
const oldest = inventors.sort(function(a, b) { const lastInventor = a.passed - a.year; const nextInventor = b.passed - b.year; return lastInventor > nextInventor ? -1 : 1; }); 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
const category = document.querySelector('.mw-category'); const links = Array.from(category.querySelectorAll('a')); const de = links .map(link => link.textContent) .filter(streetName => streetName.includes('de'));// 7. sort Exercise
// Sort the people alphabetically by last name
const alpha = people.sort((lastOne, nextOne) => { const [aLast, aFirst] = lastOne.split(', '); const [bLast, bFirst] = nextOne.split(', '); return aLast > bLast ? 1 : -1; }); console.log(alpha);// 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 transportation = data.reduce(function(obj, item) { if (!obj[item]) { obj[item] = 0; } obj[item]++; return obj; }, {}); console.log(transportation);Category: Uncategorized