Please rename "array" parameter to something else, now that it can be either an array or an integer.  Perhaps "arrayOrLength", or something neutral like "item" (since you do type dispatch later to decide what it is).

Also, I think we should return string since we don't do any HTML escaping.