Ruby Array Reduce Method Javascript