Skip to content

Instantly share code, notes, and snippets.

View bluepnume's full-sized avatar

Daniel Brain bluepnume

  • OneText
  • San Jose
View GitHub Profile
// Implement async.parallel
// It should take: 1. An array of asynchronous functions, 2. A final callback
// It should run all of the functions in parallel (just like in the ajax exercise)
// When all the calls are complete, it should call finalCallback with an array of the results from each call
// If there is any error, it should call finalCallback with the first error that comes from any of the functions
// It should only call finalCallback *one* time, either with an error, or with an array of results
async.parallel = function(functions, finalCallback) {
// Here's a mock ajax function
function ajax(url, callback) {
setTimeout(function() {
if (Math.random() < 0.25) {
callback(new Error(`Something went wrong calling ${url}`))
} else {
callback(null, {
url: url,
data: {
// Register a pair of ES6 classes called "Animal" and "Cat" *without* inheritance, so I can do:
var animal = new Animal();
animal.walk(); // logs 'The Animal walked'
var cat = new Cat();
cat.walk(); // logs 'The Cat walked'
cat.meow(); // logs 'The Cat meowed'
console.log(cat instanceof Cat); // logs true
console.log(cat instanceof Animal); // logs false
// Register a pair of ES6 classes called "Animal" and "Cat" with inheritance, so I can do:
var animal = new Animal();
animal.walk(); // logs 'The Animal walked'
var cat = new Cat();
cat.walk(); // logs 'The Cat walked'
cat.meow(); // logs 'The Cat meowed'
console.log(cat instanceof Cat); // logs true
console.log(cat instanceof Animal); // logs true
// Create a 'sayTo' function that lets you "say something to someone" like so:
let sayToJill = sayTo('Jill');
sayToJill.say('hello'); // logs 'hello Jill!'
sayToJill.say('goodbye'); // logs 'goodbye Jill!'
// Create a 'once' function that generates a new function which can only be called once
function sayHello() {
console.log('hello');
}
var sayHelloOnce = once(sayHello);
sayHelloOnce(); // logs 'hello'
sayHelloOnce(); // does nothing

xcomponent api

xcomponent.create({ ...options })

Create a component definition, which will be loaded in both the parent and child windows.

options

tag string [required]

async function makePizza(sauceType = 'red') {
let dough = makeDough();
let sauce = makeSauce(sauceType);
let cheese = grateCheese((await sauce).determineCheese());
(await dough).add(await sauce);
(await dough).add(await cheese);
return await dough;
var serialAsyncMap = function () {
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(collection, fn) {
var result, _iterator, _isArray, _i, _ref2, item;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
result = [];
_iterator = collection, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<div class="container">
<p>Choose your method of payment: </p>
<form>
<div class="radio resize">
<label>
<input type="radio" name="paymentOption" value="paypal" checked>
<img src="../img/payWithPaypal.jpg" alt="Pay with Paypal" class="paymentOptions" width="55" height="40">
</label>