Skip to main content
Back to problems
Leetcode
Medium
Functions
Arrays
Apply Transform Over Each Element In Array

Apply a given function to each element of an array and return the transformed results.

Acceptance 0%
Problem Statement

Apply Transform Over Each Element in Array

You are given an array arr and a function fn. Create a new array where each element is the result of applying fn to the corresponding element of arr.

Return the transformed array without modifying the original input array.

This is a simple function-building exercise that tests array iteration and function invocation.

Input Format

  • arr: an array of values
  • fn: a function that accepts one element from arr and returns a transformed value

Output Format

  • Return a new array result such that result[i] = fn(arr[i])

Constraints

  • Preserve the order of elements
  • Do not mutate the original array
  • The transformation function is applied independently to each element
Examples
Sample cases returned by the problem API.

Example 1

Input

arr = [1,2,3], fn = x => x + 1

Output

[2,3,4]

Explanation

Each element is increased by 1, and the results are collected in a new array.

Example 2

Input

arr = ["a","bb"], fn = s => s.length

Output

[1,2]

Explanation

The function is applied to each string, producing its length.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.