新手,问最简单的问题
我看到一段代码,作者说,是js算法,可以直接在浏览器里跑。可是我完全不会,怎么跑呢?
使用开发者工具里面的console也不行啊!
let dict = {};
function init(dep, key) {
if (dep === 0) {
dict[key] = true;
return;
}
for (let i = 0; i < 4; ++i) {
init(dep-1, key + i.toString());
}
}
function process() {
init(4, '');
for (const key in dict) {
if (dict[key]) {
for (let i = 0; i < key.length; ++i) {
for (let j = 0; j < 4; ++j) {
let temp = key.substr(0, i) + j.toString() + key.substr(i + 1);
if (temp !== key) {
dict[temp] = false;
}
}
}
}
}
Object.keys(dict).filter((key)=>dict[key]).forEach((key)=> console.log(key));
}