Minor refactorings in api.go

- Make a more generically useful "expandArray" function that can handle
  all the various transforms needed here (another one in the next cl).
- Move all the utility functions to the bottom of the file.

Test: presubmit
Merged-In: If0362c6dd90635831ac2cb2f7da336212f4c23fd
Change-Id: If0362c6dd90635831ac2cb2f7da336212f4c23fd
1 file changed