好难受呀,用js写的代码没法在这调试,我用了nodejs的输入输出,没怎么学习过nodejs,就只打算用一下他的输入输出,应付下面试题,但是现在本地的nodejs没法调试,我在vscode上搞的调试环境用不了,在控制台输入的回调函数上加断点,它不进,那位大佬有好的办法,qq1540782553,哪位大佬有兴趣可以远程看下。代码在下面
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let sum;
let flag = true;
const obj = {}
rl.on("line", function(line) {
if(flag) {
sum = line;
flag = false;
} else {
obj[line] = true;
sum--;
if(sum === 0) {
rl.close();
}
}
});
rl.on("close", function() {
for(let i=1; i<=1000; i++) {
if(obj[i]) {
console.log(i);
console.log("\n");
}
}
})
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let sum;
let flag = true;
const obj = {}
rl.on("line", function(line) {
if(flag) {
sum = line;
flag = false;
} else {
obj[line] = true;
sum--;
if(sum === 0) {
rl.close();
}
}
});
rl.on("close", function() {
for(let i=1; i<=1000; i++) {
if(obj[i]) {
console.log(i);
console.log("\n");
}
}
})
下面是vscode的launch.json配置
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Program",
"program": "${workspaceFolder}/index.js",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"type": "pwa-node"
},
]
}
全部评论
(0) 回帖