Repository navigation
docs: fix reference examples whose documented results don't match the code - #2109
Merged
Merged
Conversation
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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
🟡 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 maintake/takeRightreference docs. - Corrected multiple
compatexamples to align with actual runtime behavior (e.g.,unzipWith,nthArg,rearg,spread,mapValues). - Corrected several
compatdocumented 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
approved these changes
Oct 9, 2026
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
I ran the examples in
docs/referenceanddocs/compat/referenceagainst 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/compatexample below I also ran lodash, andes-toolkit/compatalready matches it — the code is right, the docs were not.How I found them
I extracted every
typescriptblock, 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 usesusersdefined in an earlier block, a placeholderiteratee, the browserdocument).Fixes
taketake([1, 2, 3])[1][1, 2, 3]count" sectiontakeRighttakeRight([1, 2, 3])[3][1, 2, 3]count" sectionunzipWith(a, b) => a + bover three groups['abc', 'xyz']['ab', 'xy'](a, b, c) => a + b + cnthArgarrays.map(nthArg(1))[2, 5, 8][0, 1, 2]arrays.map(array => nthArg(1)(...array))reargrearg(fn, [1, [2, 0]], 3)['b', 'c', 'a', 'd']['b', undefined, 'd', 'd']rearg(fn, [1, 2], [0, 3])spreadspread(greet, 1)withgreet(greeting, names)'Hello, Alice and Bob!'TypeError: names.join is not a functiongreet(greeting, ...names)mapValues(value, index) => value + indexon[10, 20, 30]{ '0': 10, '1': 21, '2': 32 }{ '0': '100', '1': '201', '2': '302' }value + Number(index)updatec: 13c: 16updateWithc: 13c: 19fromPairsfromPairs('invalid'){}{ i: undefined, n: undefined, … }invokeMapinvokeMap(['a', 'b', 'c'], String.prototype.toUpperCase)['A', 'B', 'C']rangerange(0, 1, 0.2)[0, 0.2, 0.4, 0.6, 0.8][0, 0.2, 0.4, 0.6000000000000001, 0.8]rangeRightrangeRight(0, 1, 0.2)[0.8, 0.6, 0.4, 0.2, 0][0.8, 0.6000000000000001, 0.4, 0.2, 0]A few of these deserve a word of explanation.
take/takeRight. The page said that omittingcounttakes one element. That is lodash's behaviour (andes-toolkit/compat's), but the maintakerequires the argument and simply slices: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:update/updateWith. Both blocks call the function twice on the sameobject, 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
invokeMappseudocode line, which is intentional and is now followed by the actual result. Every edit touches the same code lines inen,ko,jaandzh_hans, andprettier --checkpasses on all 52 files.🤖 Generated with Claude Code
https://claude.ai/code/session_0129BhQdChg7wJry7bWvRHHm