Closed
Bug 1468305
Opened 7 years ago
Closed 7 years ago
Convert lodash .chunk() to native ES6 JS
Categories
(Tree Management :: Treeherder: Frontend, enhancement, P3)
Tree Management
Treeherder: Frontend
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 | ||
Updated•7 years ago
|
Assignee | ||
Comment 1•7 years ago
|
||
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.
Comment 2•7 years ago
|
||
Updated•7 years ago
|
Attachment #8985082 -
Flags: review?(cdawson)
Comment 3•7 years ago
|
||
Comment on attachment 8985082 [details] [review]
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)
Updated•7 years ago
|
Flags: needinfo?(cdawson)
Comment 5•7 years ago
|
||
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)
Assignee | ||
Comment 6•7 years ago
|
||
Comment on attachment 8985082 [details] [review]
Link to GitHub pull-request: https://github.com/mozilla/treeherder/pull/3657
Request changes done.
Attachment #8985082 -
Flags: review?(cdawson)
Comment 7•7 years ago
|
||
Commit pushed to master at https://github.com/mozilla/treeherder
https://github.com/mozilla/treeherder/commit/8847c733736fe8a1e19e5ac65784f9ab21216781
Bug 1468305 - convert _.chunk() usages to ES6 (#3657)
Updated•7 years ago
|
Attachment #8985082 -
Flags: review?(cdawson) → review+
Comment 8•7 years ago
|
||
Thanks for the PR!
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•