Skip to content

Commit de2761d

Browse files
committed
wesbos#7 done
1 parent 48a7f00 commit de2761d

File tree

3 files changed

+114
-38
lines changed

3 files changed

+114
-38
lines changed

04 - Array Cardio Day 1/index-START.html

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,13 @@
6464
const bAge = (b.passed - b.year)
6565
return aAge > bAge ? -1 : 1
6666
}
67-
).map(i => {
68-
const fullData = {...i}
69-
fullData.age = (i.passed - i.year)
70-
return fullData
67+
).map(i => {
68+
return {
69+
...i,
70+
age: (i.passed - i.year)
71+
}
7172
})
72-
// console.table(inventorsSortedByAge)
73+
//console.table(inventorsSortedByAge)
7374

7475

7576
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
@@ -92,14 +93,22 @@
9293
// 8. Reduce Exercise
9394
// Sum up the instances of each of these
9495
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
95-
const sum = data.reduce((obj, i) => {
96-
if(!obj[i]) {
97-
obj[i] = 0
98-
}
99-
obj[i]++
100-
return obj
101-
}, {})
102-
console.log(sum)
96+
// const sum = data.reduce((obj, i) => {
97+
// if(!obj[i]) {
98+
// obj[i] = 0
99+
// }
100+
// obj[i]++
101+
// return obj
102+
// }, {})
103+
//console.log(sum)
104+
const listOfCars = data.reduce((acc, val) => {
105+
var numOfCars = acc[val] ? (acc[val]+1) : 1
106+
return {
107+
...acc,
108+
[val]: numOfCars
109+
}
110+
},{})
111+
console.log(listOfCars)
103112
</script>
104113
</body>
105114
</html>

05 - Flex Panel Gallery/index-START.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
<script>
4040
const panels = document.querySelectorAll('.panel');
41+
4142
function toggleOpen() {
4243
this.classList.toggle('open');
4344
}

07 - Array Cardio Day 2/index-START.html

Lines changed: 91 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,42 +25,108 @@
2525
];
2626

2727
// Some and Every Checks
28-
// Array.prototype.some() // is at least one person 19 or older?
29-
const someAdult = people.some(person => {
30-
const currentYear = new Date().getFullYear()
31-
//console.log(currentYear - person.year)
32-
return currentYear - person.year >= 19
33-
})
28+
// Array.prototype.some()
29+
// is at least one person 19 or older?
30+
const currentYear = new Date().getFullYear()
31+
//console.log(currentYear)
32+
const someAdult = people.some(person => (currentYear - person.year) >= 19)
3433
//console.log(someAdult)
3534

36-
// Array.prototype.every() // is everyone 19 or older?
37-
const allAdults = people.every(person => {
38-
const currentYear = new Date().getFullYear()
39-
//console.log(currentYear - person.year >= 19)
40-
return currentYear - person.year >= 19
41-
})
35+
36+
// Array.prototype.every()
37+
// is everyone 19 or older?
38+
const currentY = new Date().getFullYear()
39+
//console.log(currentY)
40+
const allAdults = people.every(person => (currentY - person.year) >= 19)
4241
//console.log(allAdults)
4342

43+
4444
// Array.prototype.find()
4545
// Find is like filter, but instead returns just the one you are looking for
4646
// find the comment with the ID of 823423
4747
const comment = comments.find(c => c.id == 823423)
48-
//console.table(comment)
48+
//console.log(comment)
49+
4950

5051
// Array.prototype.findIndex()
51-
const index = comments.findIndex(c => c.id == 823423)
52-
//console.log(index)
5352
// Find the comment with this ID
54-
// delete the comment with the ID of 823423
55-
// const newComments = comments.splice(index, 1)
56-
// console.table(newComments)
57-
// console.table(comments)
58-
59-
const newComm = [
60-
...comments.slice(0, index),
61-
...comments.slice(index+1)
62-
]
63-
console.table(newComm)
53+
const cIndex = comments.findIndex(c => c.id == 823423)
54+
//console.log(cIndex)
55+
56+
var array = [ {'a': '12', 'b':'10'}, {'a': '20', 'b':'22'} ];
57+
var newArray = array.map(x => {
58+
x.c = Number(x.a) - Number(x.b)
59+
x.d = Math.floor(x.a) - Math.floor(x.b)
60+
return x
61+
})
62+
//console.log(newArray)
63+
64+
//Filter the even numbers
65+
const arrayOfNumbers = [1,2,3,4,5,6,7,8,9]
66+
const arrayOfEvenNumbers = arrayOfNumbers.filter(n => n%2 === 0)
67+
//console.log(arrayOfEvenNumbers)
68+
const sumOfNumbers = arrayOfNumbers.reduce((acc, num) => {
69+
return acc + num
70+
}, 0)
71+
//console.log(sumOfNumbers)
72+
73+
//Do a simple string search
74+
var strings = ["hello", "Matt", "Mastodon", "Cat", "Dog"];
75+
const stringIncludes = strings.filter(s => s.includes('at'))
76+
//console.log(stringIncludes)
77+
78+
const spotifySongs = [
79+
{ id: 1, name: "Curl of the Burl", artist: "Mastodon", duration: 204 },
80+
{ id: 2, name: "Oblivion", artist: "Mastodon", duration: 306 },
81+
{ id: 3, name: "Flying Whales", artist: "Gojira", duration: 444 },
82+
{ id: 4, name: "L'Enfant Sauvage", artist: "Gojira", duration: 246 }
83+
];
84+
85+
const lastFmSongs = [
86+
{ id: 5, name: "Chop Suey", artist: "System of a Down", duration: 192 },
87+
{ id: 6, name: "Throne", artist: "Bring me the Horizon", duration: 186 },
88+
{ id: 7, name: "Destrier", artist: "Agent Fresco", duration: 132 },
89+
{ id: 8, name: "Out of the Black", artist: "Royal Blood", duration: 240 }
90+
];
91+
92+
const allSongs = [...spotifySongs, ...lastFmSongs];
93+
94+
//Transforming the given array and adding and removing properties from each object
95+
var listOfSongs = allSongs.map(song => {
96+
let {artist, ...noArtist} = song
97+
// Object.assign(noArtist, {
98+
// year: 2010
99+
// })
100+
return {
101+
...noArtist,
102+
year: 2011
103+
}
104+
})
105+
//console.log(listOfSongs)
106+
107+
const listOfSongsFiltered = allSongs.filter(s => s.artist.toLowerCase() == 'mastodon')
108+
//console.log(listOfSongsFiltered)
109+
110+
const listOfArtists = allSongs.reduce((acc, val) => {
111+
let currentArtist = val.artist
112+
let artistsSongs = acc[currentArtist] ? (acc[currentArtist] + 1) : 1
113+
return {
114+
...acc,
115+
[currentArtist]: artistsSongs
116+
}
117+
},{})
118+
//console.log(listOfArtists)
119+
120+
//Difference between let and var
121+
for (let i = 0; i < 3; i++) {
122+
//setTimeout( () => console.log('let=' + i), 3000)
123+
//console.log('var=' + i)
124+
}
125+
126+
//Now we must get a string separated by commas with all the songs that have a duration superior to 3 minutes.
127+
const arrayOfLongSongs = allSongs.filter(song => (song.duration/60) > 3).map(s => s.name )
128+
console.log(arrayOfLongSongs.join(', '))
129+
64130
</script>
65131
</body>
66132
</html>

0 commit comments

Comments
 (0)