在下面的代码中,我创建了两个具有相同值的列表:一个列表未排序 (s_not),另一个列表已排序 (s_yes)。这些值由 randint() 创建。我为每个列表运行一些循环并计时。
import random
import time
for x in range(1,9):
r = 10**x # do different val for the bound in randint()
m = int(r/2)
print("For rand", r)
# s_not is non sorted list
s_not = [random.randint(1,r) for i in range(10**7)]
# s_yes is sorted
s_yes = sorted(s_not)
# do some loop over the sorted list
start = time.time()
for i in s_yes:
if i > m:
_ = 1
else:
_ = 1
end = time.time() …Run Code Online (Sandbox Code Playgroud) 在 JavaScript 中,对象和数组的值可以像下面这样进行索引:objOrArray[index]。是否存在身份“索引”值?
换句话说:
是否有一个值x使得以下内容始终为真?
let a = [1, 2, 3, 4];
/* Is this true? */ a[x] == a
let b = { a: 1, b: 2, c: 3 };
/* Is this true? */ b[x] == b
Run Code Online (Sandbox Code Playgroud)
此上下文中身份的定义:https: //en.wikipedia.org/wiki/Identity_function
在 React 应用程序中,我通常像这样初始化 firebase:
if (firebase.apps.length < 1) {
firebase.initializeApp(firebaseConfig);
// Initialize other firebase products here
}
Run Code Online (Sandbox Code Playgroud)
在我升级到 v9 beta 之前,这一切都很完美。如何使其适用于新版本?
每次我在 Visual Studio Code 中打开项目文件夹时,每个文件的第一行都会出现错误。它找不到我的tsconfig.json文件,因为它正在查找我打开 VS Code 的目录,而不是我所在的目录eslint.json。我的根项目中有一个functions文件夹,其中包含 ESLint 配置。
这是其中的一部分:
"parserOptions": {
"ecmaVersion": 2019,
"project": ["./tsconfig.json", "./tsconfig.dev.json"],
"sourceType": "module"
},
Run Code Online (Sandbox Code Playgroud)
当我运行 lint 命令时eslint "src/*.{ts,js}",它运行良好并显示正确的警告。这意味着 VS Code 插件dbaeumer.vscode-eslint解析配置的.eslintrc.json方式与应有的不同。
如果我将 更改project为["./functions/tsconfig.json", "./functions/tsconfig.dev.json"],那么 VS Code 将停止给出错误,但是当我运行 ESLint 时,它会尝试<path/to/project>/functions/functions/tsconfig.json在函数目录中查找它两次。
这是 VS Code 的 bug、dbaeumer.vscode-eslintbug 还是我做错了什么?我可以做什么来修复该错误?