js-深复制/位操作问题
老铁们能看看这个代码有啥问题吗 比如说 需不需要用hasownproperty判断一下
function deepCopy(o,c){ var c = c || {} for(var i in o){ if(typeof o[i] === 'object'){ //要考虑深复制问题了 if(o[i].constructor === Array){ //这是数组 c[i] =[] }else{ //这是对象 c[i] = {} } deepCopy(o[i],c[i]) }else{ c[i] = o[i] } } return c }function deepCopy(o,c){
var c = c || {} for(var i in o){ if(typeof o[i] === 'object'){ //要考虑深复制问题了 if(o[i].constructor === Array){ //这是数组 c[i] =[] }else{ //这是对象 c[i] = {} } deepCopy(o[i],c[i]) }else{ c[i] = o[i] } } return c } 还有个问题当x=2015时,以下函数的返回值是多少?( )
int func(x)
{
int count = 0;
while(x)
{
count++;
x = x&(x-1);
}
return count;
}
这问题考察的是啥我想问。。。自己算一遍就出来了 但是这问题考察的是啥。。难不成是会不会位操作