【发布时间】:2019-02-18 21:48:04
【问题描述】:
我正在尝试编写一个函数sortBool(arr) 来获取一个数组并返回一个对象,其中包含找到的每种虚假值的计数。
例如:
sortBool([1, 0, 10, 2-2, Math.sqrt(-1)]); // should return {0: 2, NaN: 1}
到目前为止:
const sortBool = arr => {
index = 0;
let falsyTypes = {};
while (index < arr.length) {
if(eval(arr[index])) {
index++;
}else {
//some code to determine what type of falsy value each element is and then add it to the object
}
}
return falsyTypes;
【问题讨论】:
-
欢迎来到 Stack Overflow!如果您发布一些代码,显示您迄今为止尝试过的内容以及出现的问题,我们将能够更好地为您提供帮助。
-
I am trying to write a function在哪里?你试过什么?
标签: javascript boolean