Null type checks is not considered by the tests length
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript
- 领域
- testing
调研方向
先阅读 4-count-types.js 及其相关测试,以了解 countTypesInArray 目前如何被限制为 200 个字符。根据 issue 讨论,决定是否应显式计算 null,或是否应更改测试预期,然后验证所选行为已得到覆盖,同时不违反练习的长度要求。
由索引模型根据 Issue 内容生成。
描述
There is a problem with countTypesInArray function (4-count-types.js). The tests require a solution to be 200 signs max, but in this case, we kinda lose the check for nulls.
As you know null in JavaScript has a type of object. Thus, the implementation you require will count objects but not nulls. So, the function is not suitable for checking all the JS types.
I clearly understand that such a check can be done using a ternary operator but it's not convenient and intuitive enough.
The implementation below considers this JS's quirk:
const data = [
false,
'a',
22,
'hey',
undefined,
42,
12,
true,
{ a: 12 },
{ name: 'Jack' },
'foo',
'bar',
true,
null,
undefined,
Symbol('a'),
null
];
const countTypesInArray = data => {
const h = {};
for (const item of data) {
if (typeof item === 'object' && item === null) {
h['null'] = 1;
if (h['null'] > 0) {
h['null']++;
}
} else if (typeof item in h) {
h[typeof item]++;
} else {
h[typeof item] = 1;
}
}
return h;
};
console.log(countTypesInArray(data));
So, maybe you should consider an option for making tests a little bit more loose for null checks.
- 主要语言
- JavaScript
- 星标
- 39
- 派生
- 228
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
HowProgrammingWorks/DataTypes 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 55/100
HowProgrammingWorks/DataTypes#153 ·
-
HowProgrammingWorks/DataTypes#4 · 已指派 1 人 ·
-
难度 2/5 1-3 小时 新手友好度 48/100
-
HowProgrammingWorks/DataTypes#2 · 已指派 2 人 ·
查看 HowProgrammingWorks/DataTypes 的全部 Issue
相似的 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 70/100
babalae/bettergi-scripts-list#3674 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
vadimdemedes/ink#1029 ·
-
code-quality refactoring
难度 2/5 1-3 小时 新手友好度 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
难度 2/5 1-3 小时 新手友好度 74/100
langchain-ai/deepagents#6450 ·
-
optimization optimization:agents-md-curator
难度 2/5 1-3 小时 新手友好度 86/100
githubnext/gh-aw-cao#13143 ·