Skip to content

Instantly share code, notes, and snippets.

function shuffle(array) {
var currentIndex = array.length, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex--;
function createComponent(cmp, attributes) {
return new Promise(function(resolve, reject) {
function doCreateComponent() {
$A.createComponent(cmpDef, attributes, function(newCmp, status, errorMsg) {
if (newCmp && status === 'SUCCESS') {
resolve(newCmp);
} else if (status === 'ERROR') {
reject(errorMsg);
} else if (status === 'INCOMPLETE') {
$A.getEvt('markup://force:showOfflineMessage').fire({
@scottmo
scottmo / chainPromise.js
Last active June 24, 2019 20:16
JS Snippets
/*
* promiseSerial resolves Promises sequentially.
* Puts results into an array and get it from then()
*
* @example
* const urls = ['/url1', '/url2', '/url3']
* const funcs = urls.map(url => () => $.ajax(url))
*
* promiseSerial(funcs)
* .then(console.log.bind(console))