HowProgrammingWorks / HowProgrammingWorks/DataTypes
Null type checks is not considered by the tests length
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- JavaScript
- Estrellas
- 39
- Forks
- 228
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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.
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Empieza leyendo 4-count-types.js y las pruebas asociadas para entender cómo countTypesInArray está actualmente limitado a 200 caracteres. Decide a partir de la discusión del issue si null debe contarse explícitamente o si debe cambiar la expectativa de la prueba, y después verifica que el comportamiento elegido esté cubierto sin incumplir el requisito de longitud del ejercicio.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript
- Área
- testing
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100