Javascript Array Count With Condition In R