Javascript Function Loop Through Array Backwards Running