Created
May 16, 2020 01:02
-
-
Save royashbrook/11fcdd2d4a5150d0e1531e6717384b8e to your computer and use it in GitHub Desktop.
Random Javascript Things
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
//some utility functions. | |
const tagwrapper = (tag,txt,att='') => `<${tag}${att.length===0?'':' ' + att}>${txt}</${tag}>`; | |
const htmlhelpers = ['h4','table','thead','tbody','tr','td','th','div']; //etc | |
for(const s of htmlhelpers){eval(`var ${s} = (txt,att='')=>tagwrapper('${s}',txt,att);`)} | |
const groupByArr = (x, key) => x.reduce((rv, x)=> { (rv[x[key]] = rv[x[key]] || []).push(x); return rv; }, []); | |
const groupByObj = (x, key) => x.reduce((rv, x)=> { (rv[x[key]] = rv[x[key]] || []).push(x); return rv; }, {}); | |
const setElementHTML = (id,html) => { | |
const ctx = $(id) | |
ctx.empty(); | |
ctx.html(html) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment