Skip to content

docs: fix reference examples whose documented results don't match the code - #2109

Merged
raon0211 merged 5 commits into
toss:mainfrom
Archibald1948:docs/fix-reference-examples
Oct 9, 2026
Merged

raon0211 merged 5 commits into
toss:mainfrom
Archibald1948:docs/fix-reference-examples

Conversation

@Archibald1948

Copy link
Copy Markdown
Contributor

Summary

I ran the examples in docs/reference and docs/compat/reference against the current code and found 13 whose documented result does not match what the code returns. This fixes all of them in all four languages, bundled into one pull request as the contributing guide asks.

No shipped code changes. For every es-toolkit/compat example below I also ran lodash, and es-toolkit/compat already matches it — the code is right, the docs were not.

How I found them

I extracted every typescript block, executed each statement that is followed by // Returns:, // =>, // Result: or a same-line value comment, and deep-compared the value with the documented one. Of 2,125 checked statements, 12 did not match and 23 threw. The 13 issues below are the real ones; the rest came from running blocks in isolation (a block that uses users defined in an earlier block, a placeholder iteratee, the browser document).

Fixes

Page Example Documented Actual Fix
take take([1, 2, 3]) [1] [1, 2, 3] removed the "if you omit count" section
takeRight takeRight([1, 2, 3]) [3] [1, 2, 3] removed the "if you omit count" section
compat unzipWith (a, b) => a + b over three groups ['abc', 'xyz'] ['ab', 'xy'] iteratee takes all three: (a, b, c) => a + b + c
compat nthArg arrays.map(nthArg(1)) [2, 5, 8] [0, 1, 2] arrays.map(array => nthArg(1)(...array))
compat rearg rearg(fn, [1, [2, 0]], 3) ['b', 'c', 'a', 'd'] ['b', undefined, 'd', 'd'] rearg(fn, [1, 2], [0, 3])
compat spread spread(greet, 1) with greet(greeting, names) 'Hello, Alice and Bob!' TypeError: names.join is not a function greet(greeting, ...names)
compat mapValues (value, index) => value + index on [10, 20, 30] { '0': 10, '1': 21, '2': 32 } { '0': '100', '1': '201', '2': '302' } value + Number(index)
compat update second call in the same block c: 13 c: 16 corrected the result
compat updateWith second call in the same block c: 13 c: 19 corrected the result
compat fromPairs fromPairs('invalid') {} { i: undefined, n: undefined, … } removed the line
compat invokeMap invokeMap(['a', 'b', 'c'], String.prototype.toUpperCase) only pseudocode ['A', 'B', 'C'] added the actual result
compat range range(0, 1, 0.2) [0, 0.2, 0.4, 0.6, 0.8] [0, 0.2, 0.4, 0.6000000000000001, 0.8] corrected the result
compat rangeRight rangeRight(0, 1, 0.2) [0.8, 0.6, 0.4, 0.2, 0] [0.8, 0.6000000000000001, 0.4, 0.2, 0] corrected the result

A few of these deserve a word of explanation.

take / takeRight. The page said that omitting count takes one element. That is lodash's behaviour (and es-toolkit/compat's), but the main take requires the argument and simply slices:

export function take<T>(arr: readonly T[], count: number): T[] {
  return arr.slice(0, count);
}

take([1, 2, 3]); // [1, 2, 3] — and a type error, since `count` is required

So I removed the section rather than documenting a call the signature does not allow.

unzipWith, nthArg, rearg, spread, mapValues. Here the documented result matched what the example was trying to show, but the code did not produce it. I kept the intended result and fixed the code instead, since changing only the comment would have documented a pitfall:

// unzipWith passes one argument per group, so a two-parameter iteratee drops the third
unzipWith([['a', 'x'], ['b', 'y'], ['c', 'z']], (a, b, c) => a + b + c);
// => ['abc', 'xyz']

// Array#map calls the function with (value, index, array), so nthArg(1) picked the index
arrays.map(array => nthArg(1)(...array));
// => [2, 5, 8]

// rearg flattens its index arguments only one level deep
rearg(fn, [1, 2], [0, 3])('a', 'b', 'c', 'd');
// => ['b', 'c', 'a', 'd']

// spread(fn, 1) spreads the array at position 1 into separate arguments
function greet(greeting, ...names) {
  return `${greeting}, ${names.join(' and ')}!`;
}

// mapValues passes object keys, which are strings even for arrays
mapValues([10, 20, 30], (value, index) => value + Number(index));
// => { '0': 10, '1': 21, '2': 32 }

update / updateWith. Both blocks call the function twice on the same object, and the second comment showed the result as if the first call had not run. I corrected the number to what you get running the block top to bottom.

After the change, re-running the check leaves only the isolation artifacts described above, plus the invokeMap pseudocode line, which is intentional and is now followed by the actual result. Every edit touches the same code lines in en, ko, ja and zh_hans, and prettier --check passes on all 52 files.

🤖 Generated with Claude Code

https://claude.ai/code/session_0129BhQdChg7wJry7bWvRHHm

Archibald1948 and others added 3 commits September 17, 2026 11:08
The pages said that omitting `count` takes a single element. That is
lodash's behaviour and `es-toolkit/compat`'s, but the main `take` and
`takeRight` require `count` and simply slice, so `take([1, 2, 3])` is a
type error and returns the whole array. Remove the section in all four
languages instead of documenting a call the signature does not allow.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0129BhQdChg7wJry7bWvRHHm
…result

Running these examples gave a different result than the one shown, while
the documented result was what the example meant to demonstrate. Keep
the intended result and fix the code, in all four languages:

- unzipWith: the iteratee takes one argument per group, so use
  `(a, b, c) => a + b + c` to get `['abc', 'xyz']`.
- nthArg: `Array#map` passes `(value, index, array)`, so spread each
  array into the function to pick the second element.
- rearg: index arguments are flattened one level only, so pass
  `[1, 2], [0, 3]` instead of `[1, [2, 0]], 3`.
- spread: `spread(fn, 1)` spreads the array into separate arguments, so
  `greet` needs a rest parameter; the old example threw a TypeError.
- mapValues: keys are strings even for arrays, so convert the index with
  `Number(index)` before adding.

Every result was checked against lodash as well; the code already matches it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0129BhQdChg7wJry7bWvRHHm
Fix result comments that were wrong or missing, in all four languages:

- update, updateWith: the second call runs on an object the first call
  already changed, so the results are `c: 16` and `c: 19`, not `c: 13`.
- range, rangeRight: a 0.2 step yields `0.6000000000000001`.
- invokeMap: add the actual result after the pseudocode line.
- fromPairs: remove `fromPairs('invalid'); // {}`, which does not return
  an empty object.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0129BhQdChg7wJry7bWvRHHm
Copilot AI lite review requested due to automatic review settings September 17, 2026 02:08
@vercel

vercel Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
es-toolkit Ready Ready Preview Sep 19, 2026 8:24am UTC

Request Review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The PR still contains a duplicated invokeMap result line and take/takeRight docs continue to describe count as optional/defaulted in a way that contradicts the main entrypoint API.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR updates documentation examples (across English/Korean/Japanese/Simplified Chinese) so that the documented outputs match what es-toolkit / es-toolkit/compat actually returns, without changing shipped code.

Changes:

  • Removed incorrect “omit count” sections from main take / takeRight reference docs.
  • Corrected multiple compat examples to align with actual runtime behavior (e.g., unzipWith, nthArg, rearg, spread, mapValues).
  • Corrected several compat documented results to match real outputs (e.g., update, updateWith, range, rangeRight, invokeMap) across all 4 languages.
File summaries
File Description
docs/reference/array/take.md Removes incorrect omit-count example
docs/reference/array/takeRight.md Removes incorrect omit-count example
docs/ko/reference/array/take.md Removes incorrect omit-count example (KO)
docs/ko/reference/array/takeRight.md Removes incorrect omit-count example (KO)
docs/ja/reference/array/take.md Removes incorrect omit-count example (JA)
docs/ja/reference/array/takeRight.md Removes incorrect omit-count example (JA)
docs/zh_hans/reference/array/take.md Removes incorrect omit-count example (ZH)
docs/zh_hans/reference/array/takeRight.md Removes incorrect omit-count example (ZH)
docs/compat/reference/array/unzipWith.md Fixes iteratee arity to match actual arguments
docs/ko/compat/reference/array/unzipWith.md Fixes iteratee arity (KO)
docs/ja/compat/reference/array/unzipWith.md Fixes iteratee arity (JA)
docs/zh_hans/compat/reference/array/unzipWith.md Fixes iteratee arity (ZH)
docs/compat/reference/function/nthArg.md Fixes map usage to avoid passing index into nthArg(1)
docs/ko/compat/reference/function/nthArg.md Fixes map usage (KO)
docs/ja/compat/reference/function/nthArg.md Fixes map usage (JA)
docs/zh_hans/compat/reference/function/nthArg.md Fixes map usage (ZH)
docs/compat/reference/function/rearg.md Fixes indices example to reflect actual flattening behavior
docs/ko/compat/reference/function/rearg.md Fixes indices example (KO)
docs/ja/compat/reference/function/rearg.md Fixes indices example (JA)
docs/zh_hans/compat/reference/function/rearg.md Fixes indices example (ZH)
docs/compat/reference/function/spread.md Fixes example function signature to match spread call pattern
docs/ko/compat/reference/function/spread.md Fixes example function signature (KO)
docs/ja/compat/reference/function/spread.md Fixes example function signature (JA)
docs/zh_hans/compat/reference/function/spread.md Fixes example function signature (ZH)
docs/compat/reference/object/mapValues.md Fixes array-key handling (Number(index))
docs/ko/compat/reference/object/mapValues.md Fixes array-key handling (KO)
docs/ja/compat/reference/object/mapValues.md Fixes array-key handling (JA)
docs/zh_hans/compat/reference/object/mapValues.md Fixes array-key handling (ZH)
docs/compat/reference/object/update.md Corrects second-call result to reflect prior mutation
docs/ko/compat/reference/object/update.md Corrects second-call result (KO)
docs/ja/compat/reference/object/update.md Corrects second-call result (JA)
docs/zh_hans/compat/reference/object/update.md Corrects second-call result (ZH)
docs/compat/reference/object/updateWith.md Corrects second-call result to reflect prior mutation
docs/ko/compat/reference/object/updateWith.md Corrects second-call result (KO)
docs/ja/compat/reference/object/updateWith.md Corrects second-call result (JA)
docs/zh_hans/compat/reference/object/updateWith.md Corrects second-call result (ZH)
docs/compat/reference/object/fromPairs.md Removes invalid fromPairs('invalid') example line
docs/ko/compat/reference/object/fromPairs.md Removes invalid example line (KO)
docs/ja/compat/reference/object/fromPairs.md Removes invalid example line (JA)
docs/zh_hans/compat/reference/object/fromPairs.md Removes invalid example line (ZH)
docs/compat/reference/array/invokeMap.md Adds concrete output for function-reference example
docs/ko/compat/reference/array/invokeMap.md Adds concrete output (KO)
docs/ja/compat/reference/array/invokeMap.md Adds concrete output (JA)
docs/zh_hans/compat/reference/array/invokeMap.md Adds concrete output (ZH)
docs/compat/reference/math/range.md Corrects floating-point output example
docs/ko/compat/reference/math/range.md Corrects floating-point output example (KO)
docs/ja/compat/reference/math/range.md Corrects floating-point output example (JA)
docs/zh_hans/compat/reference/math/range.md Corrects floating-point output example (ZH)
docs/compat/reference/math/rangeRight.md Corrects floating-point output example
docs/ko/compat/reference/math/rangeRight.md Corrects floating-point output example (KO)
docs/ja/compat/reference/math/rangeRight.md Corrects floating-point output example (JA)
docs/zh_hans/compat/reference/math/rangeRight.md Corrects floating-point output example (ZH)
Review details
  • Files reviewed: 52/52 changed files
  • Comments generated: 16
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +47 to +48
// => ['A', 'B', 'C']
// => ['A', 'B', 'C']
Comment on lines 84 to +85
// Nested array indices
const rearranged = rearg(fn, [1, [2, 0]], 3);
const rearranged = rearg(fn, [1, 2], [0, 3]);
Comment on lines +47 to +48
// => ['A', 'B', 'C']
// => ['A', 'B', 'C']
Comment on lines 84 to +85
// ネストされた配列インデックス
const rearranged = rearg(fn, [1, [2, 0]], 3);
const rearranged = rearg(fn, [1, 2], [0, 3]);

#### パラメータ

- `arr` (`T[]`): 要素を取得する配列です。

#### Parameters

- `arr` (`T[]`): The array to take elements from.
Comment on lines +47 to +48
// => ['A', 'B', 'C']
// => ['A', 'B', 'C']
Comment on lines 84 to +85
// 嵌套数组索引
const rearranged = rearg(fn, [1, [2, 0]], 3);
const rearranged = rearg(fn, [1, 2], [0, 3]);

#### 参数

- `arr` (`T[]`): 要获取元素的数组。

#### 参数

- `arr` (`T[]`): 要获取元素的数组。
…t as required

- invokeMap already documented the actual result, so drop the duplicated line
- take/takeRight require count, so the parameter list should not call it optional

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…point

0.2 accumulates rounding error, so the example printed 0.6000000000000001.
A step of 0.25 is exactly representable and keeps the documented result clean.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@raon0211
raon0211 merged commit 5f7c64c into toss:main Oct 9, 2026
11 checks passed
raon0211 pushed a commit that referenced this pull request Oct 20, 2026
The page claimed that nested arrays are flattened, but `rearg` flattens
its index arguments one level only: `rearg(fn, [1, [2, 0]], 3)` leaves
`[2, 0]` as an index and yields `['b', undefined, 'd', 'd']`. #2109
corrected the example to `rearg(fn, [1, 2], [0, 3])` and left the
sentence above it untouched, which Copilot pointed out there.

Reword the sentence and the comment in all four languages.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0129BhQdChg7wJry7bWvRHHm
raon0211 pushed a commit that referenced this pull request Oct 20, 2026
`take` and `takeRight` require `count`, and #2109 removed the sections
that described omitting it while the parameter lists were corrected in
the same pull request. The headings still wrote `count?`, so make them
match the signature in all four languages.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0129BhQdChg7wJry7bWvRHHm

This branch was successfully deployed

1 active deployment
Preview — 4293b087 Deployed Sep 19, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants