var data = [
{text: 'College', id: 1},
{text: 'University', id: 2},
{text: 'School', id: 3}
];
var data = [
{text: 'College', id: 1},
{text: 'University', id: 2},
{text: 'School', id: 3}
];
data.map(function (elt, index) {
if(elt.id === 2) {
delete data[index];
}
});
var data = [
{text: 'College', id: 1},
{text: 'University', id: 2},
{text: 'School', id: 3}
];
console.log(data.length); // 3
data.map(function (elt, index) {
if(elt.id === 2) {
delete data[index];
}
});
console.log(data.length); // 3
var buttons = document.querySelectorAll("#buttons a");
function handler() {
var sel = location.hash.slice(1);
location.hash = sel || "#home";
[].slice.call(buttons).forEach(function (elt){
elt = elt.getAttribute("href").slice(1) === sel
? elt.classList.add("active")
: elt.classList.remove("active");
});
}
window.addEventListener("hashchange", handler);
window.addEventListener("load", handler);
function sieve(n) {
var a = new Array(n+1), // Тут нужно заменить на Int8Array чтобы увидеть разницу
max = Math.floor(Math.sqrt(n)),
p = 2,
i;
while (p <= max) {
for (i = 2 * p; i <= n; i += p) {
a[i] = 1;
}
while (a[++p]){}
}
while (a[n]) {
n--;
}
return n;
}
function speed(callback, arg) {
var start = Date.now();
callback(arg);
console.log("Заняло:", Date.now() - start, "ms");
}
speed(sieve, 500000);
var data = [
{text: 'College', id: 1},
{text: 'University', id: 2},
{text: 'School', id: 3}
];
data = data.filter(function (item) {
return item.id !== 2;
});