Pen Settings

HTML

CSS

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

JavaScript

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

Packages

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.

Behavior

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.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                // Simple JavaScript library for iteration algorithms
// Associated with blog post "Chains and Pipelines"
// Created by Dan Shappir @ Wix
// https://opensource.org/licenses/AAL

// Example ussage
const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
const result1 = Array.from(
  slice(
    map(
      filter(numbers, v => v % 2 === 0), v => v + 1
    ), 0, 3
  )
);

const result2 = numbers
  |> filter(#, v => v % 2 === 0)
  |> map(#, v => v + 1)
  |> slice(#, 0, 3)
  |> Array.from
            
const found = numbers
  |> filter(#, v => v * 2 > 5)
  |> head;
            
const sumOdd = numbers
  |> filter(#, v => v % 2)
  |> reduce(#, (acc, v) => acc + v, 0)
  |> tail;

document.write(`
  old style: ${result1}
  <br>
  pipeline: ${result2}
  <br>
  found: ${found}
  <br>
  sum odd: ${sumOdd}
`);

const obj = {
  a: 42,
  b: "hello",
  c: [1, 2]
};
    
const filtered = obj
  |> entries
  |> filter(#, ([, value]) => typeof value === 'number') 
  |> Object.fromEntries
  |> JSON.stringify;
    
const bigNum = [0, 1, 22, 3, 100, 5, 1000]
  |> find(#, v => v > 42);
    
document.write(`
  <br>
  filtered: ${filtered}
  <br>
  big number: ${bigNum}
`);

// Library implementation
function* map(src, op) {
  let index = 0;
  for (const value of src) {
    yield op(value, index++);
  }
}

function* filter(src, op) {
  let index = 0;
  for (const value of src) {
    if (op(value, index++)) {
      yield value;
    }
  }
}

function* slice(src, start, finish = Number.MAX_SAFE_INTEGER) {
	let index = 0;
  for (const value of src) {
    if (index >= finish) {
      break;
    }
    if (index >= start) {
      yield value;
    }
    ++index;
  }
}

function head(src) {
  for (const value of src) {
    return value;
  }
}
function tail(src) {
  let value;
  for (value of src) {}
  return value;
}
    
function find(src, op) {
  return src
    |> filter(#, op)
    |> head;
}

function* reduce(src, op, acc) {
  let index = 0;
  for (const value of src) {
    acc = op(acc, value, index++);
    yield acc;
  }
}
    
function* flat(src, depth = 1) {
  for (const value of src) {
    if (depth > 0 && value[Symbol.iterator])  {
      yield* flat(value, depth - 1);
    } else {
      yield value;      
    }
  }
}
    
function forEach(src, op) {
  let index = 0;
  for (const value of src) {
    if (op(value, index) === false) {
      break;
    }
    ++index;
  }
}
    
function* allKeys(obj = {}) {
  for (const key in obj) {
    yield key;
  }
}
function keys(obj) {
  return obj
    |> allKeys
    |> filter(#, key => obj.hasOwnProperty && obj.hasOwnProperty(key));
}
function entries(obj) {
  return obj
    |> keys
    |> map(#, key => [key, obj[key]]);
}

function reverse(src) {
  return [...src].reverse();
}
function sort(src, comp) {
  return [...src].sort(comp);
}

              
            
!
999px

Console