Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Random Javascript Things
//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
You can’t perform that action at this time.