JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
// compose helper higher order function
var compose = (...fns) => x => fns.reduceRight((y, f) => f(y), x);
// resolver helper that call function on actual value
var resolve = (value, fn) => {
if (value instanceof Promise) {
return value.then(fn);
} else {
return fn(value);
}
};
// map reducer
var map = f => reducing => (result, input) => {
return reducing(result, resolve(input, f));
};
// filtering reducer
var filter = predicate => reducing => (result, input) => {
const ret = cond => cond ? reducing(result, input) : result;
return resolve(resolve(input, predicate), ret);
}
// async aware conector function helper
var connector = fn => (accumulator, element) => {
return resolve(accumulator, (acc) => {
return resolve(element, (e) => fn(acc, e));
});
}
var concat = connector((acc, item) => acc.concat(item));
var sum = connector((a, b) => a + b);
// standard transducer
var transducer = compose(map(x => x + 1), filter(x => x % 2 === 0));
// async code
(async function() {
var promises = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(n => Promise.resolve(n));
var result = await promises.reduce(transducer(concat), Promise.resolve([]));
console.log(result);
var result = await promises.reduce(transducer(sum), Promise.resolve(0));
console.log(result);
})();
// sync code
var result = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
.reduce(transducer(concat), []);
console.log(result);
var result = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
.reduce(transducer(sum), 0);
console.log(result);
Also see: Tab Triggers