I am looking for a function that can search and filter the largest value in a nested array, and then return the parent scope.
Here is an example of my array:
data = {"people":
[{"male": [
{"name": "Bob" ,"age": "32"},
{"name":"Mike", "age":"22"}
]},
{"female": [
{"name":"Jessica", "age": "24"},
{"name":"Ann", "age": "23"}
]}]}
I want to find the highest age value among all people and then return either the male or female array (in this case it would be the male array).
In JavaScript, I could potentially use something like:
largest = array.reduce((x, y) ->
if x > y then x else y
)
console.log largest
How can I implement this logic with a nested array?
Alternatively, is there a way to utilize angular's $filter
for this task?