Accessing a property using argument returns undefined

Well I’m glad you solved it. Do you feel you understand what was going wrong before? And do you understand how the solution works completely?

From my understanding my initial code didn’t work because the name property of some of the objects were in nested objects, so my condition of a.name === 'string' was not reaching them

Here’s what the requirements are:

Check if the predicate (second argument) is truthy on all elements of a collection (first argument).

Here’s what the previous code was solving:

Check if the name property is a string AND the predicate (second argument) is truthy on all elements of a collection (first argument).

Just kinda doing some unnecessary processing.

1 Like

By the way, just taking the conditional logic out of this makes it passing.

function truthCheck(collection, pre) {
  let x = collection.map(a => a[pre])
  return x.every(e => Boolean(e))
}
1 Like

Ahh thanks a lot, this also answered my question of simply returning the values!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.