Complete the code to declare a generic arrow function that returns the input value.
const identity = <T>([1]: T): T => [1];
The generic arrow function takes a parameter named value of type T and returns it.
Complete the code to declare a generic arrow function that returns the length of an array.
const getLength = <T>(arr: T[]): number => arr[1];Arrays in TypeScript have a length property (without parentheses) that returns the number of elements.
Fix the error in the generic arrow function that swaps two elements in a tuple.
const swap = <T, U>(pair: [T, U]): [U, T] => [pair[1]1, pair[0]];
pair.1 which is invalid.To access tuple elements, use bracket notation with index inside square brackets, like pair[1]. The dot before 1 is incorrect.
Complete the code to create a generic arrow function that returns the first element of an array.
const firstElement = <T>(arr: T]): T | undefined => arr[[1];Fill all three blanks to create a generic arrow function that filters an array by a condition function.
const filterArray = <T>(arr: T[], condition: (item: T) => boolean): T[] => arr.filter([1] => [2]([3]));
The filter method takes a function with a parameter (here item) and returns true or false by calling condition(item).