var start1 = Date.now();
for (var i = 0; i < 1e10; ++i) {
}
console.log('standard', Date.now() - start1);
var start2 = Date.now();
for (var i = 1e10; i > 0; --i) {
}
console.log('reverse', Date.now() - start2);
"standard"
101
"reverse"
101
"standard"
101
"reverse"
101
"standard"
101
"reverse"
101
"standard"
101
"reverse"
101
// Code goes here
jQuery(function ($) {
var $checkbox = $(':checkbox');
var $result = $('#result');
var selected = [];
$checkbox.on('change', function () {
var $this = $(this);
var isChecked = $this.is(':checked');
var value = $this.data('value');
console.log(isChecked, value);
if (isChecked) {
selected.push(value);
} else {
selected.splice(
selected.indexOf(value),
1
);
}
setResult();
});
function setResult() {
$result.html(selected.join(', ') || 'Nothing');
}
setResult();
});
jQuery(function ($) {
var $doc = $(document);
var isDown = false;
$doc.on('mousedown', function () {
isDown = true;
});
$doc.on('mouseup', function () {
isDown = false;
});
$doc.on('keypress', function (event) {
if (isDown) {
console.log(
'pressed via mousedown',
event.which
);
}
});
});
var re = /(?:^https?:\/\/(?:www\.)?)|(?:\/$)/g;
var strings = [
'http://foo.bar',
'http://foo.bar/',
'http://www.foo.bar',
'http://www.foo.bar/',
'https://foo.bar',
'https://foo.bar/',
'https://www.foo.bar',
'https://www.foo.bar/'
];
strings.forEach(function (string) {
console.log(string.replace(re, ''));
});