Potential replacement but new ideas welcome, just created on the fly.
'use strict'
// person one
const personOne = {
name: 'Mike',
hungry: true,
food: []
}
// person two
const personTwo = {
name: 'Bernard',
hungry: false,
food: []
}
// people array
const people = [personOne, personTwo]
// function that adds food if person is hungry and makes them not hungry
const eat = function (person) {
person.food.push("Cake")
person.hungry = false
}
// function that removes food if person is not hungry and makes them hungry
const digest = function (person) {
person.food.unshift()
person.hungry = true
}
// the function should accept an array of developers and two callback functions
const runMealScript = function (arrayPeople, callBackEat, callBackDigest) {
// loop through the students array and check who is hungry
for(let i = 0; i < arrayPeople.length; i++){
// if they are hungry or not
// then pass them as an argument to the correct callback
if (arrayPeople[i].hungry === true ){
callBackEat(arrayPeople[i])
} else {
callBackDigest(arrayPeople[i])
}
}
}
// the function should get passed an array of people
// and two callback functions
runMealScript(people, eat, digest)
@jrhorn424 would like us to come up with a more pleasant example than Developers Cheating.
https://github.com/ga-wdi-boston/js-functions-ins-and-outs/blob/master/lib/school_honesty_lab.js
Potential replacement but new ideas welcome, just created on the fly.