1.A generic function
IntermediateWrite last<T>(items: readonly T[]): T | undefined and show that it returns a number for a number array and a string for a string array.
Show hint
items.at(-1) returns the last item or undefined.
Show solution
function last<T>(items: readonly T[]): T | undefined {
return items.at(-1);
}
const n = last([1, 2, 3]);
const s = last(["html", "css"]);
console.log((n ?? 0) * 10, s?.toUpperCase());30 CSS