Null type checks is not considered by the tests length
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- javascript
- Ambito
- testing
Direzione di ricerca
Inizia leggendo 4-count-types.js e i test associati per capire come countTypesInArray sia attualmente limitato a 200 caratteri. Decidi, sulla base della discussione dell’issue, se null debba essere conteggiato esplicitamente o se debba cambiare l’aspettativa del test, quindi verifica che il comportamento scelto sia coperto senza violare il requisito di lunghezza dell’esercizio.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- JavaScript
- Stelle
- 39
- Fork
- 228
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di HowProgrammingWorks/DataTypes
-
Incorrect tasks 2 and 3 Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 55/100
HowProgrammingWorks/DataTypes#153 ·
-
Bitwise operators Aperta
HowProgrammingWorks/DataTypes#4 · 1 assegnatario ·
-
Assignment operators Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 48/100
-
Arithmetic operators Aperta
HowProgrammingWorks/DataTypes#2 · 2 assegnatari ·
Tutte le issue di HowProgrammingWorks/DataTypes
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
avniproject/avni-client#2135 ·
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
babalae/bettergi-scripts-list#3674 ·
-
A-Release-Notes C-Editing D-Modest S-Ready-For-Implementation
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
bevyengine/bevy-website#2595 ·
-
ecosystem wording
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
matrix-org/matrix.org#3649 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
vadimdemedes/ink#1029 ·