parseInt('00000000000000000000000011111111', 2)
CONST1 & CONST2
. Я для таких целей использую такой генератор:function* iota() {
var i = 1;
while(true) {
yield i;
i *= 2;
}
}
var myaudio = $("#myaudio")[0];$("#myblock a").mouseenter(function(){myaudio.play();});
искомых элементов еще нет на странице, нужно так:$(function() {
var myaudio = $("#myaudio")[0];
$("#myblock a").mouseenter(function(){myaudio.play();});
});
function findParamPath(obj, prop) {
if(obj.hasOwnProperty(prop)) return prop;
var props = Object.getOwnPropertyNames(obj);
for(var i = props.length; i--; ) {
if(typeof obj[props[i]] !== 'object') continue;
var path = findParamPath(obj[props[i]], prop);
if(path) return props[i] + '.' + path;
}
return null;
}
var obj = {
object : {
client : {
name : 'Вася',
phone : '799999999'
},
order : {
param1 : '2122',
param2 : '1231'
}
}
};
console.log(findParamPath(obj, 'name')); // 'object.client.name'
console.log(findParamPath(obj, 'param1')); // 'object.order.param1'
console.log(findParamPath(obj, 'unknown')); // null (не найдено)
this.items = [
{name : 'Petya', id: 1, active: false},
{name : 'Vasjya', id: 2, active: false},
{name : 'Dima', id: 3, active: false},
{name : 'Lena', id: 4, active: false},
{name : 'Katya', id: 5, active: false}
];
this.itemsIndex = _.indexBy(this.items, 'id');
this.items2 = [
{name : 'Dima', id: 3},
{name : 'Lena', id: 5},
];
this.items2.forEach(el => {
if(el.id in this.itemsIndex) {
this.itemsIndex[el.id].active = true;
}
});
function MainFoo () {
var myVar;
AsyncFoo().then(function(result) {
myVar = result;
});
}
function AsyncFoo() {
return new Promise(function(resolve, reject) {
setTimeout(function(){
resolve(100);
}, 5000)
});
}
async function MainFoo () {
var myVar = await AsyncFoo();
}
function AsyncFoo() {
return new Promise(function(resolve, reject) {
setTimeout(function(){
resolve(100);
}, 5000)
});
}
function createCompare(field) {
return function (a, b){
if(a[field] > b[field]) return 1;
if(a[field] < b[field]) return -1;
return 0;
}
}
users.sort(createCompare('name'));
function lookUp(firstName, prop){
for(var i = 0; i < contacts.length; i++) {
if(contacts[i].firstName === firstName) {
if(!contacts[i].hasOwnProperty(prop)) {
return "No such property";
}
return contacts[i][prop];
}
}
return "No such contact";
}