JSFiddle - React, Tailwind, and code Playground
HTML
<div>something</div>
<div>another</div>
<div>something else</div>
<div>is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the lea</div>
JavaScript
// New map with support for objects. It would be super duper fantasterific!
// Just like http://documentcloud.github.com/underscore/#map
// http://bugs.jquery.com/ticket/2616
// JS Perf test: http://jsperf.com/old-map-vs-new-map-with-obj-support
$.new_map_each = function(elems, callback, arg) {
var ret = [],
value;
$.each(elems, function(key, value) {
value = callback(value, key, arg);
if (value != null) {
ret[ret.length] = value;
}
});
return ret.concat.apply([], ret);
}
$.new_map_forin = function(elems, callback, arg) {
var ret = [],
value;
// Go through the array, translating each of the items to their
// new value (or values).
if(jQuery.isPlainObject(elems)){
for ( name in elems ) {
value = callback( elems[ name ], name, arg);
if ( value != null ) {
ret[ ret.length ] = value;
}
}
}
else {
for ( var i = 0, length = elems.length; i < length; i++ ) {
value = callback( elems[ i ], i, arg );
if ( value != null ) {
ret[ ret.length ] = value;
}
}
}
return ret.concat.apply( [], ret );
}
$.new_map_forin_2 = function(elems, callback, arg) {
var ret = [],
value,
length = elems.length,
isObj = elems.length === undefined;
// Go through the array, translating each of the items to their
// new value (or values).
if(isObj){
for ( name in elems ) {
value = callback( elems[ name ], name, arg);
if ( value != null ) {
ret[ ret.length ] = value;
}
}
}
else {
for ( var i = 0; i < length; i++ ) {
value = callback( elems[ i ], i, arg );
if ( value != null ) {
ret[ ret.length ] = value;
}
}
}
return ret.concat.apply( [], ret );
}
$.each(['map',...