Javascript Array Count Elements In A Vector In Physics