我正在学习编码,这只是一个练习。任何导致负数的操作都会显示错误,但console.logs会显示正确。\n这是为什么?
\n<!DOCTYPE html>\n<html>\n\n<head>\n <meta charset="utf-8">\n <meta name="viewport" content="width=device-width">\n <title>replit</title>\n<style>\n\n#calculator{\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n max-width:400px;\n min-width: 300px;\n background-color: green;\n}\n\n#screen{\n width: 100%; \n aspect-ratio: 4/1.5;\n background-color: rgba(0, 0, 0, 0.8);\n}\n\n#input{\n width:90%;\n height:90%;\n background-color:rgba(0, 0, 0, 0); \n color:white;\n font-size: 15vw;\n direction: rtl;\n font-family: Helvetica, sans-serif;\n}\n\n#buttonsGrid{\n width: 100%;\n aspect-ratio: 4/5;\n display: grid;\n grid-template-columns: repeat(4, 1fr);\n grid-template-rows: repeat(5, 1fr);\n justify-content: center;\n font-size: 5vw;\n color:white;\n background-color: gray;\n font-family: Helvetica, sans-serif;\n}\n\n.singleButton{\n border: solid;\n border-color: black;\n border-width: 1px;\n display: flex;\n align-items: center;\n …Run Code Online (Sandbox Code Playgroud) 我正在尝试遍历以下嵌套对象并获得如下输出:
const preference = {
"ethnicity": {
"value": "Gurung",
"rank": 1
},
"occupation": {
"value": "Banker",
"rank": 2
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试了以下操作:
let preferenceRank = {};
preference.map(pref => {
preferenceRank[pref.rank] = pref;
});
console.log(preferenceRank);
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
"TypeError: preference.map is not a function"...
Run Code Online (Sandbox Code Playgroud)
所需输出:
{
1: "ethnicity",
2: "occupation",
}
Run Code Online (Sandbox Code Playgroud) 所以我知道要获得一个专栏,我必须写
a = list(zip(*f)[0])
Run Code Online (Sandbox Code Playgroud)
结果a将是一个包含f中列表中第一个元素的列表.
如何为每个列表获取多个元素?我试过了
a = list(zip(*f)[1:19])
Run Code Online (Sandbox Code Playgroud)
但它只返回了一个列表列表,其中内部列表由每个列表中的第i个元素组成.
XNOR我在编写最多包含 7 个~和运算符的按位函数时遇到困难|。例子:bitXnor(6, -5) = 2。如果没有 ,我该如何做到这一点&?
到目前为止我有这个:
int bitXnor(int x, int y) {
return ~(~x | ~y);
Run Code Online (Sandbox Code Playgroud)
但我收到错误:
int bitXnor(int x, int y) {
return ~(~x | ~y);
Run Code Online (Sandbox Code Playgroud) javascript ×2
bitwise-xor ×1
c ×1
calculator ×1
html ×1
list ×1
numpy ×1
python ×1
xor ×1
zip ×1