This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {uniqueId} from 'lodash' // optional | |
/** | |
* @param {String} file The path of the file you want to load. | |
* @param {Function} callback (optional) The function to call when the script loads. | |
* @param {String} id (optional) The unique id of the file you want to load. | |
*/ | |
export const loadAsyncScript = (file, callback, id) => { | |
const d = document | |
if (!id) { id = uniqueId('async_script') } // optional | |
if (!d.getElementById(id)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Write some code, that will flatten an array of arbitrarily nested arrays | |
of integers into a flat array of integers. e.g. [[1,2,[3]],4] -> [1,2,3,4] | |
I use JS in ES6 Syntax | |
Tested in Chrome, Firefox and Safari | |
*/ | |
let flatten = [] | |
evaluate = (el=[0,[[1, 2],[3]],[4,[[5,6]]]])=>{ | |
el.map(n=>n instanceof Array ? evaluate(n) : flatten = [...flatten,n]) | |
} |