Question: How can I get the following Julia code to work (counting adults in a house) using count() instead of the for loop?

```
mutable struct Person
    age
end
mutable struct House
    people::Array{Person}
end
function Adults(h::House)
    numAdults = 0
    for n in 1:length(h.people)
        if h.people[n].age > 18; numAdults = numAdults + 1; end
    end
    numAdults
# count(h.people.age > 18, h.people) is there some variant of this that works?    
end
p1 = Person(10)
p2 = Person(40)
h1 = House([p1, p2])
Adults(h1)

```

Answer: 
In this case `Boolean` is a function that returns true if the "thing in the array is truthy" and return false if the "thing in the array is falsy"

When you call `filter` every array element will have `Boolean(the element)` called on it and the result determines if the element makes it into the output array. Your array only has values `true` and `false` and `Boolean()` will return true for your `true` values and false for your `false` values. The result is the falses are filtered out. 

`Boolean()` will also return true for non boolean values like `1` or `"a"`, and false for non boolean non-values like `null` or `undefined`, so this approach would filter

```
[true, false, 1, "a", {}, null, undefined]

```

To

```
[true, 1, "a", {}]

```
Every value in the array will be passed to the `Boolean()` object wrapper, and it will `cast (convert)` values to `true` or `false`.

This is the same as:

```js
const countTrue = r => r.filter(item => Boolean(item)).length

// Boolean(true) is true
// Boolean(false) is false
// Boolean(123) is true
// Boolean(0) is false

```

From [MDN Docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean):

> 
> The value passed as the first parameter is converted to a boolean value, if necessary. If the value is omitted or is 0, -0, null, false, NaN, undefined, or the empty string (""), the object has an initial value of false. All other values, including any object, an empty array ([]), or the string "false", create an object with an initial value of true.
> 
> 
>