I want to find the maximum of a nested array, something like this:
a = [[1,2],[20,3]]
d3.max(d3.max(a)) // 20
but my array contains a text field that I want to discard:
a = [["yz",1,2],["xy",20,3]]
d3.max(a) // 20
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you have a nested array of numbers (
arrays = [[1, 2], [20, 3]]), nest d3.max:Or equivalently, use array.map:
If you want to ignore string values, you can use array.filter to ignore strings:
Alternatively, if you know the string is always in the first position, you could use array.slice which is a bit more efficient:
Yet another option is to use an accessor function which returns
NaNfor values that are not numbers. This will cause d3.max to ignore those values. Conveniently, JavaScript’s built-inNumberfunction does exactly this, so you can say: