Given an n x m array of boolean:
[[true, true, false],
[false, true, true],
[false, true, true]]
what is a simple way that can return “how many true are there in that column?”
the result should be
[1, 3, 2]
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.
Use transpose to get an array where each subarray represents a column and then map each column to the number of
trues in it:Here’s a version with inject that should run on 1.8.6 without any dependencies: