first<T> works for any array type.
Goal
Log the first city and the first unit count.
function first<T>(items: T[]): T {
return items[0];
}
console.log(first(["Nairobi", "Mombasa"]));
console.log(first([12, 8, 5]));function last<T>(items: T[]): T {
return items[items.length - 1];
}
console.log(last(["Kisumu", "Nakuru"]));interface Box<T> {
value: T;
}
const box: Box<string> = { value: "Eldoret" };
console.log(box.value);function pair<A, B>(a: A, b: B): [A, B] {
return [a, b];
}
console.log(pair("Nairobi", 12));