Array Generic Annotations
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, PromiseThe generic Array syntax works seamlessly with other generic patterns. For example, Promise<Array<string>> clearly represents a promise that resolves to a string array. The generic syntax is essential when working with complex types like Observable<Array<User>> or Map<string, Array<number>>.
TypeScript's array types support all standard JavaScript array methods with proper type inference. Methods like push(), pop(), map(), and filter() are fully typed, returning the correct element type.
The Array<T> syntax is particularly useful when T is a complex type, making the code more readable than T[] in some contexts. TypeScript style guides often prefer the generic syntax for consistency.
Example Input & Output
Algorithm Flow

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
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;
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
