Skip to content

Instantly share code, notes, and snippets.

@jcblw
Last active October 29, 2016 09:03
Show Gist options
  • Save jcblw/b98873cfa488c6968a97 to your computer and use it in GitHub Desktop.
Save jcblw/b98873cfa488c6968a97 to your computer and use it in GitHub Desktop.
requirebin sketch
// async-each MIT license (by Paul Miller from http://paulmillr.com).
(function(globals) {
'use strict';
var each = function(items, next, callback) {
if (!Array.isArray(items)) throw new TypeError('each() expects array as first argument');
if (typeof next !== 'function') throw new TypeError('each() expects function as second argument');
if (typeof callback !== 'function') callback = Function.prototype; // no-op
if (items.length === 0) return callback(undefined, items);
var transformed = new Array(items.length);
var count = 0;
var returned = false;
items.forEach(function(item, index) {
next(item, function(error, transformedItem) {
if (returned) return;
if (error) {
returned = true;
return callback(error);
}
transformed[index] = transformedItem;
count += 1;
if (count === items.length) return callback(undefined, transformed);
});
});
};
if (typeof define !== 'undefined' && define.amd) {
define([], function() {
return each;
}); // RequireJS
} else if (typeof module !== 'undefined' && module.exports) {
module.exports = each; // CommonJS
} else {
globals.asyncEach = each; // <script>
}
})(this);
function formatNumber(number){var x=""+number;return recursiveAddComma(x.trim().split("")).join("").replace(/^,/,"")}function recursiveAddComma(remaining,results){var last=remaining.slice(-3,remaining.length);var _remaining=remaining.slice(0,-3);if(typeof results==="undefined"){results=[]}last.unshift(",");if(_remaining.length>3){return recursiveAddComma(_remaining,last.concat(results))}return _remaining.concat(last.concat(results))}console.log(formatNumber(1e3));console.log(formatNumber(1e14));console.log(formatNumber(666666));console.log(formatNumber("oiwoijfawieofj"));
{
"name": "requirebin-sketch",
"version": "1.0.0",
"dependencies": {
"vsvg": "1.9.1",
"vsvg-paths": "1.0.0"
}
}
<!-- contents of this file will be placed inside the <body> -->
<!-- contents of this file will be placed inside the <head> -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment