Closed Bug 1468305 Opened 6 years ago Closed 6 years ago

Convert lodash .chunk() to native ES6 JS

Categories

(Tree Management :: Treeherder: Frontend, enhancement, P3)

enhancement

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: evct, Assigned: evct, Mentored)

References

Details

Attachments

(1 file)

Converting all _.chunk() (lodash) functions to ES6 JS
Assignee: nobody → oss
Blocks: 1466494
Status: NEW → ASSIGNED
Priority: -- → P3
I wrote this piece of code, it seems to do the job: const myArray = ['a', 'b', 'c', 'd']; const chunked1 = myArray.reduce((acc, val, idx, arr, chunkSize = 2) => !(idx % chunkSize) ? acc.concat([arr.slice(idx, idx + chunkSize)]) : acc, []); console.log(chunked1); // => [['a', 'b'], ['c', 'd']] const chunked2 = myArray.reduce((acc, val, idx, arr, chunkSize = 3) => !(idx % chunkSize) ? acc.concat([arr.slice(idx, idx + chunkSize)]) : acc, []); console.log(chunked2); // => [['a', 'b', 'c'], ['d']] I will implement this within the week (unless there are remarks), along with the other bugs I've opened lately.
Attachment #8985082 - Flags: review?(cdawson)
Comment on attachment 8985082 [details] Link to GitHub pull-request: https://github.com/mozilla/treeherder/pull/3657 Let's just import the ``chunk`` function from ``lodash`` directly and continue to use it. I think it'll be clearer in this case than doing a complex ``reduce``. The import should be: import chunk from 'lodash/chunk'; Thanks!
Flags: needinfo?(cdawson)
Attachment #8985082 - Flags: review?(cdawson)
Still awaiting code updates on this PR.
Flags: needinfo?(cdawson)
Flags: needinfo?(cdawson)
Oops, I just noticed you can re-assign to me when you've made your updates. I'll let you do that instead of n-i'ing myself. :)
Flags: needinfo?(cdawson)
Comment on attachment 8985082 [details] Link to GitHub pull-request: https://github.com/mozilla/treeherder/pull/3657 Request changes done.
Attachment #8985082 - Flags: review?(cdawson)
Attachment #8985082 - Flags: review?(cdawson) → review+
Thanks for the PR!
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: