JSFiddle - React, Tailwind, and code Playground
JavaScript
var isInteger1 = function(a) {
return ((typeof a !== 'number') || (a % 1 !== 0)) ? false : true;
};
var isInteger2 = function(possibleInteger) {
return Object.prototype.toString.call(possibleInteger) !== "[object Array]" && /^[\d]+$/.test(possibleInteger);
}
var loadTest = function(fn, value) {
var start = new Date;
for(var i=0; i<1000000; i++) {
fn(value);
}
return new Date - start;
};
var compare = function(testValues, i) {
var value = testValues[i];
var time1 = loadTest(isInteger1, value);
var time2 = loadTest(isInteger2, value);
$('body').append('<p>'+value+' => '+time1+'ms vs '+time2+'ms</p>');
if(i < testValues.length-1) {
setTimeout(function() {
compare(testValues, i+1);
}, 10);
}
};
var testValues = [1, 1.1, '1', [1], {foo:'bar'}];
compare(testValues, -1);