Skip to content

Instantly share code, notes, and snippets.

View JoxieMedina's full-sized avatar
🏠
Working from home

Darwin Medina JoxieMedina

🏠
Working from home
  • CTI
  • Honduras
View GitHub Profile
@JoxieMedina
JoxieMedina / scriptLoaderES6.js
Last active August 10, 2018 01:47 — forked from jtpaasch/loader.js
Javascript module for loading scripts asynchronously.
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)) {
@JoxieMedina
JoxieMedina / nested_to_flatten.js
Last active January 12, 2018 18:37
Arbitrarily nested arrays of integers into a flat array of integers
/*
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])
}