I need to implement the mapping function using reduce.
Requirements:
- The
mapfunction should apply afnfunction to every element inarray. arrayshould not be mutated
This is my code so far (I'm checking if the array is empty):
function map<A, B>(array: A[], fn: (a: A) => B): B[] {
if (array.length === 0) {
return [];
}
}
Would appreciate any help!
.map()?