Apply a Function on a List
Apply mathematical, string, or custom JavaScript functions to every item in a list. Transform, filter, and aggregate data instantly.
x = current value, i = index (0-based)
Results will appear here after applying a function.
About
Batch-processing a list through a function is a fundamental operation in data manipulation, yet manual application across hundreds of values invites transcription errors and costs hours. This tool applies a selected transformation f(x) to each element x in your input list, returning the mapped output in O(n) time. It supports over 40 built-in mathematical, string, and type-conversion functions, plus a custom expression mode where you write raw JavaScript using x (current value) and i (index). Filtering functions like isPrime or isEven return boolean masks. Aggregation functions collapse the list into a single statistic. Note: custom expressions execute via new Function() with a capped iteration guard. The tool does not sandbox against all side-effects. Do not paste untrusted code.
Formulas
The core operation is a map transformation applied element-wise across an input list of length n:
For aggregation functions like mean, the result collapses to a scalar:
Population variance used for variance:
Custom expressions receive x (current value) and i (zero-based index) as parameters. The expression is compiled once via new Function('x','i', "return " + expr) and invoked per element. Factorial is computed iteratively: n! = nβk=1 k, capped at n β€ 170 to stay within IEEE 754 double precision range.
Reference Data
| Category | Function | Input Example | Output Example | Notes |
|---|---|---|---|---|
| Math | square | 5 | 25 | x2 |
| Math | cube | 3 | 27 | x3 |
| Math | sqrt | 16 | 4 | Returns NaN for negatives |
| Math | abs | β7 | 7 | Absolute value |
| Math | factorial | 6 | 720 | Max n = 170 |
| Math | log10 | 1000 | 3 | Base-10 logarithm |
| Math | ln | 2.718 | ≈1 | Natural logarithm |
| Math | exp | 2 | 7.389 | ex |
| Math | reciprocal | 4 | 0.25 | 1 Γ· x |
| Math | negate | 5 | β5 | βx |
| Math | double | 8 | 16 | 2 Γ x |
| Math | halve | 10 | 5 | x Γ· 2 |
| Math | floor | 3.7 | 3 | Round down |
| Math | ceil | 3.2 | 4 | Round up |
| Math | round | 3.5 | 4 | Nearest integer |
| Math | sign | β42 | β1 | Returns β1, 0, or 1 |
| String | uppercase | hello | HELLO | Locale-aware |
| String | lowercase | WORLD | world | Locale-aware |
| String | capitalize | hello world | Hello World | Each word capitalized |
| String | reverse | abc | cba | Character reversal |
| String | length | hello | 5 | Character count |
| String | trim | hi | hi | Strips whitespace |
| String | slugify | Hello World | hello-world | URL-safe format |
| Type | toBinary | 10 | 1010 | Base-2 string |
| Type | toHex | 255 | ff | Base-16 string |
| Type | toOctal | 8 | 10 | Base-8 string |
| Type | toCharCode | A | 65 | First char code |
| Filter | isEven | 4 | TRUE | Divisible by 2 |
| Filter | isOdd | 3 | TRUE | Not divisible by 2 |
| Filter | isPrime | 7 | TRUE | Trial division up to sqrt(n) |
| Filter | isPositive | 5 | TRUE | x > 0 |
| Filter | isNegative | β3 | TRUE | x < 0 |
| Aggregate | sum | [1,2,3] | 6 | Collapses to single value |
| Aggregate | mean | [2,4,6] | 4 | Arithmetic mean |
| Aggregate | median | [1,3,5] | 3 | Middle value (sorted) |
Frequently Asked Questions
new Function('x', "i", "return " + yourExpression). The variable x holds the current list element (auto-cast to a number if numeric), and i is the zero-based index. You can use any standard Math methods, e.g., Math.pow(x, 3) + i. The function is compiled once and invoked per element. A try-catch guards each call, so one failing element won't crash the entire batch - it returns an error marker for that position.parseFloat(). If parsing fails (returns NaN), mathematical functions propagate NaN for that element, which is displayed as "NaN" in the output. String functions treat the raw string value. Filter functions like isEven return FALSE for non-numeric inputs. This preserves the positional mapping between input and output lists.Math.round(Math.sqrt(x)) combines sqrt and round.