Wednesday, October 28, 2015

Extracts a word which starts with a given substring

// extracts js_* class
$(anySelector).attr('class').match(/\bjs_[^\b]*?\b/)[0]; 

Wednesday, June 17, 2015

Remove duplicates in an array


[1,1,2,2,3,3,4].reduce(function (a,b) { if (a.indexOf(b) < 0) a.push(b); return a;},[]);

will return [1,2,3,4]

In case of arrays composed of JSON objects use this expression for the "if"clause:

(JSON.stringify(a).indexOf(JSON.stringify(b))

Tuesday, May 12, 2015

Brackground-color transitions

With a tiny jQuery plugin and CSS3 is possible to create programmatic background color transitions.

See this page for "easing" possible values.