Code Logo

Array Generic Annotations

Published at24 Jul 2026
TypeScript Functions Easy 1 views
Like0

Write a TypeScript function that uses the generic Array<string> syntax. Create a function that joins an array of strings with a separator. The parameter must be typed as Array<string>.

TypeScript supports two syntaxes for typed arrays: string[] and Array<string>. The generic Array<T> syntax is consistent with other generic types like Promise<T> and Map<K, V>.

Using the generic Array syntax makes the type parameter explicit and is preferred in some TypeScript style guides for consistency with other generic types.

The generic Array syntax works seamlessly with other generic patterns. For example, Promise

Example Input & Output

Example 1
Input
["x","y"], " "
Output
"x y"
Example 2
Input
["a","b","c"], ","
Output
"a,b,c"

Algorithm Flow

Recommendation Algorithm Flow for Array Generic Annotations

Solution Approach

Write a TypeScript function that uses the generic Array<string> syntax. Create a function that joins an array of strings with a separator. The parameter must be typed as Array<string>.

TypeScript supports two syntaxes for typed arrays: string[] and Array<string>. The generic Array<T> syntax is consistent with other generic types like Promise<T> and Map<K, V>.

Using the generic Array syntax makes the type parameter explicit and is preferred in some TypeScript style guides for consistency with other generic types.

Best Answers

typescript - Approach 1
function joinStrings(items: Array<string>, separator: string): string {
    if (items.length === 0) return '';
    var result = items[0];
    for (var i = 1; i < items.length; i++) {
        result += separator + items[i];
    }
    return result;
}