Javascript Array Count Function In R