Inverse of a Function
copy const expoIn = t => ( t== 0 ) ? 0 : Math .pow ( 2 , 10 * ( t - 1 ) ) const expoInInverse= t => ( t== 0 ) ? 0 : ( ( Math .log ( t) + 10 * Math .log ( 2 ) ) / Math .log ( 2 ) ) / 10 console.log ( expoIn( .35) + ' ' + expoInInverse( expoIn( .35) ) )
Try it out…
Very nice inverse function calculator by user fawad over at Wolfram Alpha . Was attempting to invert a standard “exponential in” easing function – after some futzing I resorted to the calculator 😀
Mangler
copy const lookupReplacements = { // entities (like ∑ or Θ - are safer // than just putting things inline like ∑ or ® 'a' : [ 'A' , 'Ä' , '∆' , 'á' ] , 'e' : [ 'é' , '∃' ] , 't' : [ '⊤' , 'Τ' ] , 'b' : [ 'β' ] , 'o' : [ '∅' , '_o_' ] } function mangle( s) { return s.split ``.map ( letter => { const chars = lookupReplacements[ letter] return chars ? chars[ Math .floor ( chars.length * Math .random ( ) ) ] : letter } ) .join `` } document.body .innerHTML = mangle( 'Been taking a break from making snippets... might start up again...<hr>' ) document.body .innerHTML += mangle( 'Been taking a break from making snippets... might start up again...<hr>' ) document.body .innerHTML += mangle( 'Been taking a break from making snippets... might start up again...<hr>' )
Try it out
Substitute some characters in a string with some random choices…
Mutation Observer
copy // Select the node that will be observed for mutations const targetNode = document.getElementById ( 'some-id' ) ; // Options for the observer (which mutations to observe) const config = { attributes: true , childList: true , subtree: true } ; // Callback function to execute when mutations are observed const callback = function ( mutationsList, observer) { // Use traditional 'for loops' for IE 11 (goodbye IE11!!!!) for ( const mutation of mutationsList) { if ( mutation.type === 'childList' ) { console.log ( 'A child node has been added or removed.' ) ; } else if ( mutation.type === 'attributes' ) { console.log ( 'The ' + mutation.attributeName + ' attribute was modified.' ) ; } } } ; // Create an observer instance linked to the callback function const observer = new MutationObserver( callback) ; // Start observing the target node for configured mutations observer.observe ( targetNode, config) ; // Later, you can stop observing observer.disconnect ( ) ;
This is pure gold if you haven’t used it… (from MDN)