我已经检查过此页面:mozilla 文档
我不明白为什么索引 0 带有:
const object3 = { 100: 'a', 2: 'b', 7: 'c' };
console.log(Object.entries(object3)[0]);
// expected output: Array ["100", "a"] <== i thought of this
Run Code Online (Sandbox Code Playgroud)
相反,文档说你得到:
// expected output: Array ["2", "b"]
Run Code Online (Sandbox Code Playgroud)
有人可以解释一下为什么吗?
我试图弄清楚这个程序是如何工作的,我陷入了While循环,我不明白第二个循环如何退出,因为它v永远不会等于0或负数.既然这是唯一可以退出该循环的条件,还是我错过了更深层次的东西?代码将整数(> 0)转换为二进制.
public class Binary {
public static void main(String[] args) {
// read in the command-line argument
int n = Integer.parseInt(args[0]);
// set v to the largest power of two that is <= n
int v = 1;
while (v <= n/2) {
v = v * 2;
}
// check for presence of powers of 2 in n, from largest to smallest
while (v > 0) {
// v is not present in n
if (n …Run Code Online (Sandbox Code Playgroud)