Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <h1>JS: Map() and Filter() implemented by Reduce()</h1>
<div id="explanation">
	<p>In the [BETA] freeCodeCamp/Javascript/Functional Programming module, there is a series of waypoints discussing the <a href="">Array.prototype</a> methods
		<a href="">map()</a>, <a href="">filter()</a>,
		and <a href="">reduce()</a>. In the last one, it states:
			The <code>reduce</code> method allows for more general forms of array processing, and it's possible to show that both <code>filter</code> and <code>map</code> can be derived as a special application of <code>reduce</code>.
		The purpose of this CodePen is to prove that to myself, and to you. The javascript code demonstrates that.
<div id="result-arrays">
	<p id="original"></p>
	<p id="mapped"></p>
	<p id="filtered"></p>
	<p id="reduce-mapped"></p>
	<p id="reduce-filtered"></p>


                body{ margin: auto 15px; }
h1{text-align: center;}

@media (min-width: 600px){
		display: grid;
			"heading heading"
			"discussion results";
		grid-template-rows: auto 1fr;
		grid-template-columns: 1fr 300px;
		grid-gap: 15px;
	h1{ grid-area: heading; }
	#explanation{ grid-area: discussion; }
	#result-arrays{ grid-area: results; }

@media (min-width: 700px){
	body{ grid-template-columns: 1fr 1fr; }

@media (min-width: 1160px){
			"leftGutter heading heading rightGutter"
			"leftGutter discussion results rightGutter";
		grid-template-columns: 1fr 500px 500px 1fr;


                function insertArrayIntoElementWithLabel(id, label, arr){
	//id is the element ID
	//label is the string that comes before the "stringified" array.
	//arr is an array of integers
	document.getElementById(id).innerHTML = `${label}: `+arr.join(", ");

const consecutiveNums =[];
for (let i=0; i<10; i++){
insertArrayIntoElementWithLabel("original", "Original Array", consecutiveNums);
insertArrayIntoElementWithLabel("mapped", "Mapped to Squares",
	(elem) => elem*elem
insertArrayIntoElementWithLabel("filtered", "Filtered by Evens", consecutiveNums.filter(
	(elem) => elem%2==0
insertArrayIntoElementWithLabel("reduce-mapped", "Mapped to Squares using Reduce", consecutiveNums.reduce(
	(newArr, elem) => newArr.concat(elem*elem), []
insertArrayIntoElementWithLabel("reduce-filtered", "Filtered by Evens using Reduce", consecutiveNums.reduce(
	(newArr, elem) => newArr.concat(elem%2==0 ? elem : []), []