Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions data/assignments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
let assignments =[
{
name: 'week-07-perfect-lineup',
completed: false
},
{
name: 'week-06-10-10-10',
completed: false
},
{
name: 'week-04-fantasy-scoring',
completed: true
},
{
name: 'week-06-hazy-calculator',
completed: true
}
]
module.exports = {
assignments
}
95 changes: 85 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,34 @@

Declaring an Array with Objects

1) Declare and initialize an array of `assignments` with `name` and `completed` properties. Name the array `assignments`. `completed` will have boolean values.
1) Declare and initialize an array of
`assignments` with `name` and `completed` properties.
Name the array `assignments`. `completed` will have boolean values.

*/

/*let assignments =[
{
name: 'week-07-perfect-lineup',
completed: false
},
{
name: 'week-06-10-10-10',
completed: false
},
{
name: 'week-04-fantasy-scoring',
completed: true
},
{
name: 'week-06-hazy-calculator',
completed: true
}
]

module.exports = {
assignments
}
*/

/**

Expand All @@ -20,31 +44,82 @@


*/


const { assignments } = require('./data/assignments')
console.log(assignments)
/**

Looping and using references to arrays a given positions

3) Loop through the data using a for loop. Just console.log within the loop to show each item within the array
3) Loop through the data using a for loop.
Just console.log within the loop to show each item within the array

*/
for ( let index = 0; index < assignments.length; index = index + 1 ) {
const assignment = assignments[index]
console.log({ assignment })
}
//for.Each option
assignments.forEach( (assignment) => {
console.log({ assignment })
} )

/**

Looping and Assignment

4) Declare a new array named `allAssignments`. Loop through the `assignments` array data using a for loop and assign each item from `assignments` to the new `allAssignments` array
4) Declare a new array named `allAssignments`.
Loop through the `assignments` array data using a
for loop and assign each item from `assignments`
to the new `allAssignments` array

*/


let allAssignments = []
/*for (const index in assignments) {
const assignment = assignments[index]
allAssignments.push(assignment)
}
console.log({ allAssignments }) */
// forEach option
/*assignments.forEach( (assignment) => {
allAssignments.push(assignment)
})
console.log({allAssignments}) */

allAssignments = assignments.map( (assignment) => {
return assignment
} )
console.log(allAssignments)
/**


Filtering

5) Declare a new array named `completedAssignments`. Loop through the `assignments` array data using a for loop. Use a condition to only add to `allAssignments` where there are property values with `completed` of `true`
5) Declare a new array named `completedAssignments`.
Loop through the `assignments` array data using a for loop.
Use a condition to only add to `completedAssignments` where
there are property values with `completed` of `true`

*/


/*let completedAssignments = []
completedAssignments = assignments.filter( (assignment) => {
let {completed} = assignment;
return completed
} )
console.log(completedAssignments)*/
/*let completedAssignments = []
completedAssignments = assignments.map( (assignment) => {
if (completed = true)
return assignment.completed
})
console.log(completedAssignments)*/

let completedAssignments = []
for(const index in assignments) {
const assignment = assignments[index]

if (assignment.completed) {
completedAssignments.push(assignment)
}
}
console.log({completedAssignments})