Trace a map, filter, or reduce call element by element, showing the output array or accumulator build up at each step.
You are an instructor who noticed that `map`, `filter`, and `reduce` confuse beginners not because the concept is hard, but because most explanations show only the starting array and the finished result, with the actual element-by-element transformation happening invisibly in between, and your explanations never skip that middle part. My language is [LANGUAGE:select:JavaScript,Python], and my function is [FUNCTION:select:map,filter,reduce]. My own code is [CODE?], if I have a specific call I want traced, and if I left it blank, generate a short array of five to seven simple values and a small callback function appropriate to [FUNCTION] for me instead. State the starting array and the callback function clearly before tracing anything. Then process the array one element at a time, in order, and for each element, show three things, the current element being processed, what the callback function does with it, and the resulting effect on the output. For `map`, show the current element going in, the transformed value coming out, and the new array so far with that value appended. For `filter`, show the current element, the boolean result of the test condition applied to it, and whether it was kept in or dropped from the result array so far. For `reduce`, show the current element, the accumulator's value before this step, the computation combining the accumulator with the current element, and the accumulator's new value after this step, since watching the accumulator change is the part that makes `reduce` click when nothing else does. Continue until every element has been processed, then state the final result clearly on its own line, whether that is a new array for `map` or `filter`, or a single final value for `reduce`. If my own [CODE] included a `reduce` call without an explicit starting value for the accumulator, point that out directly and explain what the accumulator's actual starting value becomes by default, the first element of the array, and how that changes which element the trace begins processing from, since a missing starting value is one of the most common sources of an unexpected result with `reduce`. Close by asking whether I want to see the same array processed by a different one of the three functions, since watching `map`, `filter`, and `reduce` handle the identical starting data makes the distinct role each one plays much clearer than reading about them separately.
Use this prompt anywhere
10,000+ expert prompts for ChatGPT, Claude, Gemini, and wherever you use AI.
Get Early AccessDiscover more prompts that could help with your workflow.
Build a small working program that calls a real public API, with the request, response, and API key setup explained step by step.
Explain a core functional programming idea, such as pure functions or immutability, with a broken code example and its fixed version shown side by side.
Explain a built-in math function, square root, power, absolute value, or rounding, covering math and syntax, then generate practice calls to predict before revealing results.
10,000+ expert-curated prompts for ChatGPT, Claude, Gemini, and wherever you use AI. Our extension helps any prompt deliver better results.