TheAlgorithms/JavaScript · error · TypeError
Arguments are not all numbers.
Error message
Arguments are not all numbers.
What it means
Thrown by `zellersCongruenceAlgorithm(day, month, year)` when any of the three arguments fails `typeof === 'number'`. The Gregorian-date formula uses arithmetic on all three, so non-numbers break it. The check is type-only - NaN passes and yields garbage.
Source
Thrown at Maths/ZellersCongruenceAlgorithm.js:8
// Zeller's Congruence Algorithm finds the day of the week from the Gregorian Date. Wikipedia: https://en.wikipedia.org/wiki/Zeller%27s_congruence
export const zellersCongruenceAlgorithm = (day, month, year) => {
if (
typeof day !== 'number' ||
typeof month !== 'number' ||
typeof year !== 'number'
) {
throw new TypeError('Arguments are not all numbers.')
}
const q = day
let m = month
let y = year
if (month < 3) {
m += 12
y -= 1
}
day =
(q +
Math.floor((26 * (m + 1)) / 10) +
(y % 100) +
Math.floor((y % 100) / 4) +
Math.floor(Math.floor(y / 100) / 4) +
5 * Math.floor(y / 100)) %
7
const days = [
'Saturday',View on GitHub (pinned to 5c39e87a9a)
Solutions
- Coerce all three arguments with `Number(...)` and verify each is a finite integer.
- When reading from a Date object, use `.getDate()`, `.getMonth() + 1`, `.getFullYear()` (all numbers).
- Validate range (1-31 day, 1-12 month, positive year) in addition to type.
Example fix
// before
zellersCongruenceAlgorithm(req.query.day, req.query.month, req.query.year)
// after
const [d, m, y] = [req.query.day, req.query.month, req.query.year].map(Number)
if (![d, m, y].every((v) => Number.isInteger(v))) throw new TypeError('all date parts must be integers')
zellersCongruenceAlgorithm(d, m, y) Defensive patterns
Strategy: type-guard
Validate before calling
const [d, m, y] = [day, month, year].map(Number)
if (![d, m, y].every((v) => typeof v === 'number' && Number.isInteger(v))) {
throw new TypeError('day, month, year must all be integers')
}
zellersCongruenceAlgorithm(d, m, y) Type guard
const isInt = (x) => typeof x === 'number' && Number.isInteger(x)
Prevention
- Use Date methods (getDate, getMonth+1, getFullYear) which return numbers.
- Coerce URL/query params with Number() before forwarding.
- Validate ranges (day 1-31, month 1-12) in addition to type.
When it happens
Trigger: Call `zellersCongruenceAlgorithm('1', 1, 2020)`, `zellersCongruenceAlgorithm(1, 'Jan', 2020)`, `zellersCongruenceAlgorithm(1, 1, null)`, or any case where a Date component is stringified.
Common situations: Date components read from URL params, CSV cells, or `Date` parts passed as strings; mixing the function with `moment.format('M')` (string) outputs.
Related errors
- Argument not an Integer
- Provided input is not an array
- Invalid capacity
- Rule must be an integer between the values 0 and 255 (got ${
- Coefficient a, b should be number
AI-assisted analysis of TheAlgorithms/JavaScript@5c39e87a9a (2026-08-13).
Data as JSON: /api/errors/e464fa7e82a6b650.
Report an issue: GitHub.