squareRoot(6) returns 3, squareRoot(12) returns 4; test expects squareRoot(3, 1) = 1.8 (correct: 1.7)
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- javascript
- Área
- testing-qa
Línea de trabajo
Empieza con src/algorithms/math/square-root/squareRoot.js y la expectativa que falla en squareRoot.test.js:30; compara la condición de terminación del bucle con los ejemplos del issue. Ejecuta las pruebas de raíz cuadrada y comprueba las entradas indicadas, incluida squareRoot(3, 1). El trabajo estará listo cuando los resultados se redondeen correctamente y se resuelva el bloqueo notificado en #2187.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
src/algorithms/math/square-root/squareRoot.js stops Newton's iteration when |number - root²| <= 10^-tolerance (line 31). That bounds the error of the square, not of the root. Newton's method approaches √n from above, so the loop stops on an overestimate, and rounding then goes the wrong way.
squareRoot(6); // 3 expected 2 (√6 = 2.449)
squareRoot(12); // 4 expected 3 (√12 = 3.464)
squareRoot(3, 1); // 1.8 expected 1.7 (√3 = 1.732)
squareRoot.test.js:30 asserts expect(squareRoot(3, 1)).toBe(1.8), so the test enshrines the bug. For n = 0..3000 and tolerance 0..6 there are 68 wrong results.
Fix: iterate until the root stops decreasing (while (next < root)), then round. Checked on 259,695 inputs against correctly rounded Math.sqrt; the only mismatches are 53 last-digit float effects at tolerance >= 10. This also removes the hang reported in #2187 (squareRoot(65549, 11)). The #2187 change alone still returns 3 and 1.8.
Found during an independent property-based audit of this repo (full report and reproducible harness: https://github.com/devladpopov/algorithm-autopsy/tree/main/autopsy-02).
- Lenguaje dominante
- JavaScript
- Estrellas
- 197k
- Forks
- 31k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
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.
Más de trekhleb/javascript-algorithms
-
[Docs]: 9 hotlinked images in algorithm READMEs return 404 (GeeksforGeeks + ivanyu.me uploads)Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
trekhleb/javascript-algorithms#2225 ·
-
BinarySearchTreeNode removingPosiblemente ocupada @bbonch la tomó hace 260 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
trekhleb/javascript-algorithms#2102 · 1 comentario ·
-
math: uniquePaths and leastCommonMultiple return non-integers below 2^53; iterative Euclid is subtraction-based and can hangPosiblemente ocupada @Shubham-Padkonde la tomó hace 3 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
trekhleb/javascript-algorithms#2238 ·
-
Trie.deleteWord fails for words containing characters outside the BMP (e.g. emoji)Posiblemente ocupada @Shubham-Padkonde la tomó hace 3 días. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 35/100
trekhleb/javascript-algorithms#2237 ·
-
bellmanFord: runs in O(V²·E) rather than the O(V·E) / O(E) stated in READMEPosiblemente ocupada @Shubham-Padkonde la tomó hace 3 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 35/100
trekhleb/javascript-algorithms#2236 ·
Todos los issues de trekhleb/javascript-algorithms
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
Los mantenedores suelen responder en 1 día
-
bug needs-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
apex-dev-tools/apex-log-parser#199 ·
Los mantenedores suelen responder en 1 día
-
enhancement good first issue hacktoberfest help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
ReadBufferStream.addBuffer adds the full ArrayBuffer of a typed array view, and ignores its byteOffsetPosiblemente ocupada @wayfarer3130 la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Expo 57 example: pnpm install fails with ERR_PNPM_TRUST_DOWNGRADEPosiblemente ocupada @github-actions la tomó hoy. Abiertobug react-native team/client-libraries
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
PostHog/posthog-js#5442 · 1 comentario ·
Los mantenedores suelen responder en 1 día