HowProgrammingWorks / HowProgrammingWorks/DataTypes

Null type checks is not considered by the tests length

未關閉
#63 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

主要語言
JavaScript
星號
39
分支
228
PR 合併指標
30 天內沒有已合併 PR

描述

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.

貢獻指南

這個儲存庫沒有索引到貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

先閱讀 4-count-types.js 及其相關測試,以了解 countTypesInArray 目前如何被限制為 200 個字元。根據 issue 討論,決定是否應明確計算 null,或是否應變更測試預期,然後驗證所選行為已受到涵蓋,同時不違反練習的長度要求。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
javascript
領域
testing
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。