Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                console.clear();

// ======== BASIC ========
console.group('basics');

// ### Example function
const createChallenge = (name, opponent, game) => {
  console.log(`${name} is challenging ${opponent} to play a game of ${game}!`);
};

// ### Curried version of example function
const curriedChallengeBasic = name => {
  return opponent => {
      return game => {
        // console.log(`${name}, is challenging ${opponent} to play a game of ${game}!`);
        createChallenge(name, opponent, game);
      };
  };
};

createChallenge('Chantal', 'Mark', 'chess');
curriedChallengeBasic('John')('Sam')('set');

console.groupEnd();
// ======== GENERATED CURRY ========
console.group('generated curry');

const curry = (functionToCurry) => {
  const waitForArguments = (...attrs) => {
    return attrs.length === functionToCurry.length ?
      functionToCurry(...attrs) :
      (...nextAttrs) => waitForArguments(...attrs, ...nextAttrs);
  };

  return waitForArguments;
};

const curriedChallengeGenerated = curry(createChallenge);

curriedChallengeGenerated('Rob')('Patricia')('rummikub');
curriedChallengeGenerated('Mary', 'Linda', 'skip-bo');

console.groupEnd();
// ======== CURRY WITH ARITY ========
console.group('Curry with arity');

const curryWithArity = (functionToCurry, arity = functionToCurry.length) => {
  const waitForArguments = (...attrs) => {
    return attrs.length >= arity ?
      functionToCurry(...attrs) :
      (...nextAttrs) => waitForArguments(...attrs, ...nextAttrs);
  };

  return waitForArguments;
};

const sumTo100 = (...args) => {
  const sum = args.reduce((total, number) => total + number);
  console.log(`${args.join(' + ')}`, sum === 100);
};

const sumTo100In2Parts = curryWithArity(sumTo100, 2);
sumTo100In2Parts(20, 80); // true
sumTo100In2Parts(40)(60); // true

const sumTo100In5Parts = curryWithArity(sumTo100, 5);
sumTo100In5Parts(10, 20, 30, 10, 30); // true
const firstThree = sumTo100In5Parts(10, 20, 30); // function waiting for arguments
firstThree(10, 30); // true

console.groupEnd();
// ======== CURRY WITH PLACEHOLDERS ========
console.group('Curry with placeholders');
const _ = Symbol();

const curryWithPlaceholder = (functionToCurry, numberOfArguments = functionToCurry.length) => {
  const waitForArguments = (...attrs) => {
    const waitForMoreArguments = (...nextAttrs) => {
      const filledAttrs = attrs.map(attr => {
        // if any of attrs is placeholder _, nextAttrs should first fill that
        return attr === _ && nextAttrs.length ?
          nextAttrs.shift() :
          attr;
      });
      return waitForArguments(...filledAttrs, ...nextAttrs);
    };

    // wait for all arguments to be present and not skipped
    return attrs.filter(arg => arg !== _).length >= numberOfArguments ?
      functionToCurry(...attrs) :
      waitForMoreArguments;
  };

  return waitForArguments;
};

const curriedChallengeWithPlaceholder = curryWithPlaceholder(createChallenge);

const playScrabble = curriedChallengeWithPlaceholder(_, _, 'scrabble');
const playTicTacToe = curriedChallengeWithPlaceholder(_, _, 'tic tac toe');

playScrabble('Amy', 'James');
playScrabble('Ben', 'Nicole');
playTicTacToe('Anna', 'Joyce');
playTicTacToe('Thomas', 'Daniel');

console.groupEnd();
              
            
!
999px

Console