I am wondering if someone can explain to my why this is allowed more specifically why I don't need to say in notes.filter(notesCheck) what obj needs to be. The function works fine in this manner.
var duplicateNotes = notes.filter(notesCheck)
function notesCheck(obj) {
if (obj.title === note.title) {
console.log("duplicate found")
return true
}
}
I read https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/filter but didn't really gleam an explanation from it.
Summary filter() calls a provided callback function once for each element in an array, and constructs a new array of all the values for which callback returns a value that coerces to true. callback is invoked only for indexes of the array which have assigned values; it is not invoked for indexes which have been deleted or which have never been assigned values. Array elements which do not pass the callback test are simply skipped, and are not included in the new array.
callback is invoked with three arguments:
the value of the element the index of the element the Array object being traversed
filter,map,reducefunctions yourself or find other people's implementations to understand the inner workings of these methods.