Was said test asking for the shortest possible answer or simply testing your coding ability? Not to be pedantic, they aren't the same. Those of us who have to communicate with other programmers, write or maintain code, or teach, may disagree with your concept of 'better answer'.
I'd prefer a three line solution above that used a foreach simply for readability.