Use JavaScript or Lodash to create multi dimensional array
I want to create a multi-dimensional array like this using Lodash or vanilla JS:
[
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
[11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
etc
]
This is a simplistic example since I want this pattern to continue up to 1,000,000 but for demonstration 1 to 20 is fine.
Any ideas? I've tried _.range(20)
so far but I need this Array to be multi-dimensional. Thanks
javascript lodash
add a comment |
I want to create a multi-dimensional array like this using Lodash or vanilla JS:
[
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
[11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
etc
]
This is a simplistic example since I want this pattern to continue up to 1,000,000 but for demonstration 1 to 20 is fine.
Any ideas? I've tried _.range(20)
so far but I need this Array to be multi-dimensional. Thanks
javascript lodash
What happened when you tried_.range(20)
? Perhaps you'd then be interested in_.chunk()
– Phil
Nov 20 '18 at 23:54
1
Pure JS:Array.from(new Array(30)).map((_, i) => i + 1).reduce((acc, v) => v % 10 === 1 ? [...acc, [v]] : (acc[Math.floor((v - 1) / 10)].push(v), acc), )
– zerkms
Nov 20 '18 at 23:58
add a comment |
I want to create a multi-dimensional array like this using Lodash or vanilla JS:
[
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
[11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
etc
]
This is a simplistic example since I want this pattern to continue up to 1,000,000 but for demonstration 1 to 20 is fine.
Any ideas? I've tried _.range(20)
so far but I need this Array to be multi-dimensional. Thanks
javascript lodash
I want to create a multi-dimensional array like this using Lodash or vanilla JS:
[
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
[11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
etc
]
This is a simplistic example since I want this pattern to continue up to 1,000,000 but for demonstration 1 to 20 is fine.
Any ideas? I've tried _.range(20)
so far but I need this Array to be multi-dimensional. Thanks
javascript lodash
javascript lodash
asked Nov 20 '18 at 23:49


danday74danday74
18.8k1491130
18.8k1491130
What happened when you tried_.range(20)
? Perhaps you'd then be interested in_.chunk()
– Phil
Nov 20 '18 at 23:54
1
Pure JS:Array.from(new Array(30)).map((_, i) => i + 1).reduce((acc, v) => v % 10 === 1 ? [...acc, [v]] : (acc[Math.floor((v - 1) / 10)].push(v), acc), )
– zerkms
Nov 20 '18 at 23:58
add a comment |
What happened when you tried_.range(20)
? Perhaps you'd then be interested in_.chunk()
– Phil
Nov 20 '18 at 23:54
1
Pure JS:Array.from(new Array(30)).map((_, i) => i + 1).reduce((acc, v) => v % 10 === 1 ? [...acc, [v]] : (acc[Math.floor((v - 1) / 10)].push(v), acc), )
– zerkms
Nov 20 '18 at 23:58
What happened when you tried
_.range(20)
? Perhaps you'd then be interested in _.chunk()
– Phil
Nov 20 '18 at 23:54
What happened when you tried
_.range(20)
? Perhaps you'd then be interested in _.chunk()
– Phil
Nov 20 '18 at 23:54
1
1
Pure JS:
Array.from(new Array(30)).map((_, i) => i + 1).reduce((acc, v) => v % 10 === 1 ? [...acc, [v]] : (acc[Math.floor((v - 1) / 10)].push(v), acc), )
– zerkms
Nov 20 '18 at 23:58
Pure JS:
Array.from(new Array(30)).map((_, i) => i + 1).reduce((acc, v) => v % 10 === 1 ? [...acc, [v]] : (acc[Math.floor((v - 1) / 10)].push(v), acc), )
– zerkms
Nov 20 '18 at 23:58
add a comment |
4 Answers
4
active
oldest
votes
With lodash you can use chunk
:
const result = _.chunk(_.range(1, 21), 10);
console.log(result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js"></script>
1
Just a minor correction... OP's arrays start at1
– Phil
Nov 20 '18 at 23:57
@Phil thanks, corrected.
– slider
Nov 20 '18 at 23:58
1
Upvote! First thing I though about when I read the question and then realized you already wrote it :)
– Akrion
Nov 21 '18 at 0:48
add a comment |
Using nested native Array#from()
const
limit = 100,
fr = Array.from;
const res = fr({ length:limit/10 }, (_,i) => fr({ length:10 }, (_,j) => i*10 + j+1 ));
console.log(res)
2
That's really really really really cool
– zerkms
Nov 21 '18 at 0:04
1
Array#from()
👈 spot the Java dev ;-)
– Phil
Nov 21 '18 at 0:05
I know OP doesn't mention, but what if thelimit
isn't a multiple of 10, say 25? Slider's answer handles that case via chunking
– Phil
Nov 21 '18 at 0:07
@Phil right...I assumed even 10's based on 20 and 1,000,000
– charlietfl
Nov 21 '18 at 0:09
2
It's not as pretty, but you could have something like{length:Math.min(10, limit-(i*10))}
in the inside loop to handle non-even groupings.
– Mark Meyer
Nov 21 '18 at 0:16
|
show 2 more comments
With vanilla javascript:
x =
for (i=1; i<=20; i=i+10) {
y =
for (j=0; j<10; j++) {
y.push(i + j)
}
x.push(y)
}
console.log(x)
For anyone who's interested, I time clocked these answers and this is the fastest. Using 1 million entries, this clocks at .100 seconds. Lodash chunk clocks close behind at .110s. Array.from
lags behind at .254s.
Old school cool :)
– slider
Nov 21 '18 at 0:15
1
@Phil hah, fixed... and time-clocked
– Conner
Nov 21 '18 at 0:33
add a comment |
Looking at the ES6 Array.from
documentation you can see a range generator function:
const range = (start, stop, step) => Array.from({ length: (stop -
start) / step }, (_, i) => start + (i * step));
So with that in mind you could generate the range via:
range(1, 21, 1) // account for the 0 with the 21 otherwise you get 1-19
Then all that is missing is the chunk
function:
const range = (start, stop, step) => Array.from({ length: (stop - start) / step }, (_, i) => start + (i * step));
const chunkBy = (arr, by=2) => arr.reduce((r,c,i) => (i%by==0 ? r.push([c]) : r[r.length-1] = [...r[r.length-1], c], r), )
console.log(chunkBy(range(1,21,1), 10))
The chunkBy
uses Array.reduce
& the %
operator to chunk
the data.
1
And you wrote a mini lodash :D
– slider
Nov 21 '18 at 0:50
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53403334%2fuse-javascript-or-lodash-to-create-multi-dimensional-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
With lodash you can use chunk
:
const result = _.chunk(_.range(1, 21), 10);
console.log(result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js"></script>
1
Just a minor correction... OP's arrays start at1
– Phil
Nov 20 '18 at 23:57
@Phil thanks, corrected.
– slider
Nov 20 '18 at 23:58
1
Upvote! First thing I though about when I read the question and then realized you already wrote it :)
– Akrion
Nov 21 '18 at 0:48
add a comment |
With lodash you can use chunk
:
const result = _.chunk(_.range(1, 21), 10);
console.log(result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js"></script>
1
Just a minor correction... OP's arrays start at1
– Phil
Nov 20 '18 at 23:57
@Phil thanks, corrected.
– slider
Nov 20 '18 at 23:58
1
Upvote! First thing I though about when I read the question and then realized you already wrote it :)
– Akrion
Nov 21 '18 at 0:48
add a comment |
With lodash you can use chunk
:
const result = _.chunk(_.range(1, 21), 10);
console.log(result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js"></script>
With lodash you can use chunk
:
const result = _.chunk(_.range(1, 21), 10);
console.log(result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js"></script>
const result = _.chunk(_.range(1, 21), 10);
console.log(result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js"></script>
const result = _.chunk(_.range(1, 21), 10);
console.log(result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js"></script>
edited Nov 20 '18 at 23:58
answered Nov 20 '18 at 23:56
sliderslider
8,25811130
8,25811130
1
Just a minor correction... OP's arrays start at1
– Phil
Nov 20 '18 at 23:57
@Phil thanks, corrected.
– slider
Nov 20 '18 at 23:58
1
Upvote! First thing I though about when I read the question and then realized you already wrote it :)
– Akrion
Nov 21 '18 at 0:48
add a comment |
1
Just a minor correction... OP's arrays start at1
– Phil
Nov 20 '18 at 23:57
@Phil thanks, corrected.
– slider
Nov 20 '18 at 23:58
1
Upvote! First thing I though about when I read the question and then realized you already wrote it :)
– Akrion
Nov 21 '18 at 0:48
1
1
Just a minor correction... OP's arrays start at
1
– Phil
Nov 20 '18 at 23:57
Just a minor correction... OP's arrays start at
1
– Phil
Nov 20 '18 at 23:57
@Phil thanks, corrected.
– slider
Nov 20 '18 at 23:58
@Phil thanks, corrected.
– slider
Nov 20 '18 at 23:58
1
1
Upvote! First thing I though about when I read the question and then realized you already wrote it :)
– Akrion
Nov 21 '18 at 0:48
Upvote! First thing I though about when I read the question and then realized you already wrote it :)
– Akrion
Nov 21 '18 at 0:48
add a comment |
Using nested native Array#from()
const
limit = 100,
fr = Array.from;
const res = fr({ length:limit/10 }, (_,i) => fr({ length:10 }, (_,j) => i*10 + j+1 ));
console.log(res)
2
That's really really really really cool
– zerkms
Nov 21 '18 at 0:04
1
Array#from()
👈 spot the Java dev ;-)
– Phil
Nov 21 '18 at 0:05
I know OP doesn't mention, but what if thelimit
isn't a multiple of 10, say 25? Slider's answer handles that case via chunking
– Phil
Nov 21 '18 at 0:07
@Phil right...I assumed even 10's based on 20 and 1,000,000
– charlietfl
Nov 21 '18 at 0:09
2
It's not as pretty, but you could have something like{length:Math.min(10, limit-(i*10))}
in the inside loop to handle non-even groupings.
– Mark Meyer
Nov 21 '18 at 0:16
|
show 2 more comments
Using nested native Array#from()
const
limit = 100,
fr = Array.from;
const res = fr({ length:limit/10 }, (_,i) => fr({ length:10 }, (_,j) => i*10 + j+1 ));
console.log(res)
2
That's really really really really cool
– zerkms
Nov 21 '18 at 0:04
1
Array#from()
👈 spot the Java dev ;-)
– Phil
Nov 21 '18 at 0:05
I know OP doesn't mention, but what if thelimit
isn't a multiple of 10, say 25? Slider's answer handles that case via chunking
– Phil
Nov 21 '18 at 0:07
@Phil right...I assumed even 10's based on 20 and 1,000,000
– charlietfl
Nov 21 '18 at 0:09
2
It's not as pretty, but you could have something like{length:Math.min(10, limit-(i*10))}
in the inside loop to handle non-even groupings.
– Mark Meyer
Nov 21 '18 at 0:16
|
show 2 more comments
Using nested native Array#from()
const
limit = 100,
fr = Array.from;
const res = fr({ length:limit/10 }, (_,i) => fr({ length:10 }, (_,j) => i*10 + j+1 ));
console.log(res)
Using nested native Array#from()
const
limit = 100,
fr = Array.from;
const res = fr({ length:limit/10 }, (_,i) => fr({ length:10 }, (_,j) => i*10 + j+1 ));
console.log(res)
const
limit = 100,
fr = Array.from;
const res = fr({ length:limit/10 }, (_,i) => fr({ length:10 }, (_,j) => i*10 + j+1 ));
console.log(res)
const
limit = 100,
fr = Array.from;
const res = fr({ length:limit/10 }, (_,i) => fr({ length:10 }, (_,j) => i*10 + j+1 ));
console.log(res)
edited Nov 21 '18 at 1:20
answered Nov 21 '18 at 0:03
charlietflcharlietfl
139k1388120
139k1388120
2
That's really really really really cool
– zerkms
Nov 21 '18 at 0:04
1
Array#from()
👈 spot the Java dev ;-)
– Phil
Nov 21 '18 at 0:05
I know OP doesn't mention, but what if thelimit
isn't a multiple of 10, say 25? Slider's answer handles that case via chunking
– Phil
Nov 21 '18 at 0:07
@Phil right...I assumed even 10's based on 20 and 1,000,000
– charlietfl
Nov 21 '18 at 0:09
2
It's not as pretty, but you could have something like{length:Math.min(10, limit-(i*10))}
in the inside loop to handle non-even groupings.
– Mark Meyer
Nov 21 '18 at 0:16
|
show 2 more comments
2
That's really really really really cool
– zerkms
Nov 21 '18 at 0:04
1
Array#from()
👈 spot the Java dev ;-)
– Phil
Nov 21 '18 at 0:05
I know OP doesn't mention, but what if thelimit
isn't a multiple of 10, say 25? Slider's answer handles that case via chunking
– Phil
Nov 21 '18 at 0:07
@Phil right...I assumed even 10's based on 20 and 1,000,000
– charlietfl
Nov 21 '18 at 0:09
2
It's not as pretty, but you could have something like{length:Math.min(10, limit-(i*10))}
in the inside loop to handle non-even groupings.
– Mark Meyer
Nov 21 '18 at 0:16
2
2
That's really really really really cool
– zerkms
Nov 21 '18 at 0:04
That's really really really really cool
– zerkms
Nov 21 '18 at 0:04
1
1
Array#from()
👈 spot the Java dev ;-)– Phil
Nov 21 '18 at 0:05
Array#from()
👈 spot the Java dev ;-)– Phil
Nov 21 '18 at 0:05
I know OP doesn't mention, but what if the
limit
isn't a multiple of 10, say 25? Slider's answer handles that case via chunking– Phil
Nov 21 '18 at 0:07
I know OP doesn't mention, but what if the
limit
isn't a multiple of 10, say 25? Slider's answer handles that case via chunking– Phil
Nov 21 '18 at 0:07
@Phil right...I assumed even 10's based on 20 and 1,000,000
– charlietfl
Nov 21 '18 at 0:09
@Phil right...I assumed even 10's based on 20 and 1,000,000
– charlietfl
Nov 21 '18 at 0:09
2
2
It's not as pretty, but you could have something like
{length:Math.min(10, limit-(i*10))}
in the inside loop to handle non-even groupings.– Mark Meyer
Nov 21 '18 at 0:16
It's not as pretty, but you could have something like
{length:Math.min(10, limit-(i*10))}
in the inside loop to handle non-even groupings.– Mark Meyer
Nov 21 '18 at 0:16
|
show 2 more comments
With vanilla javascript:
x =
for (i=1; i<=20; i=i+10) {
y =
for (j=0; j<10; j++) {
y.push(i + j)
}
x.push(y)
}
console.log(x)
For anyone who's interested, I time clocked these answers and this is the fastest. Using 1 million entries, this clocks at .100 seconds. Lodash chunk clocks close behind at .110s. Array.from
lags behind at .254s.
Old school cool :)
– slider
Nov 21 '18 at 0:15
1
@Phil hah, fixed... and time-clocked
– Conner
Nov 21 '18 at 0:33
add a comment |
With vanilla javascript:
x =
for (i=1; i<=20; i=i+10) {
y =
for (j=0; j<10; j++) {
y.push(i + j)
}
x.push(y)
}
console.log(x)
For anyone who's interested, I time clocked these answers and this is the fastest. Using 1 million entries, this clocks at .100 seconds. Lodash chunk clocks close behind at .110s. Array.from
lags behind at .254s.
Old school cool :)
– slider
Nov 21 '18 at 0:15
1
@Phil hah, fixed... and time-clocked
– Conner
Nov 21 '18 at 0:33
add a comment |
With vanilla javascript:
x =
for (i=1; i<=20; i=i+10) {
y =
for (j=0; j<10; j++) {
y.push(i + j)
}
x.push(y)
}
console.log(x)
For anyone who's interested, I time clocked these answers and this is the fastest. Using 1 million entries, this clocks at .100 seconds. Lodash chunk clocks close behind at .110s. Array.from
lags behind at .254s.
With vanilla javascript:
x =
for (i=1; i<=20; i=i+10) {
y =
for (j=0; j<10; j++) {
y.push(i + j)
}
x.push(y)
}
console.log(x)
For anyone who's interested, I time clocked these answers and this is the fastest. Using 1 million entries, this clocks at .100 seconds. Lodash chunk clocks close behind at .110s. Array.from
lags behind at .254s.
x =
for (i=1; i<=20; i=i+10) {
y =
for (j=0; j<10; j++) {
y.push(i + j)
}
x.push(y)
}
console.log(x)
x =
for (i=1; i<=20; i=i+10) {
y =
for (j=0; j<10; j++) {
y.push(i + j)
}
x.push(y)
}
console.log(x)
edited Nov 21 '18 at 0:32
answered Nov 21 '18 at 0:01
ConnerConner
23.3k84568
23.3k84568
Old school cool :)
– slider
Nov 21 '18 at 0:15
1
@Phil hah, fixed... and time-clocked
– Conner
Nov 21 '18 at 0:33
add a comment |
Old school cool :)
– slider
Nov 21 '18 at 0:15
1
@Phil hah, fixed... and time-clocked
– Conner
Nov 21 '18 at 0:33
Old school cool :)
– slider
Nov 21 '18 at 0:15
Old school cool :)
– slider
Nov 21 '18 at 0:15
1
1
@Phil hah, fixed... and time-clocked
– Conner
Nov 21 '18 at 0:33
@Phil hah, fixed... and time-clocked
– Conner
Nov 21 '18 at 0:33
add a comment |
Looking at the ES6 Array.from
documentation you can see a range generator function:
const range = (start, stop, step) => Array.from({ length: (stop -
start) / step }, (_, i) => start + (i * step));
So with that in mind you could generate the range via:
range(1, 21, 1) // account for the 0 with the 21 otherwise you get 1-19
Then all that is missing is the chunk
function:
const range = (start, stop, step) => Array.from({ length: (stop - start) / step }, (_, i) => start + (i * step));
const chunkBy = (arr, by=2) => arr.reduce((r,c,i) => (i%by==0 ? r.push([c]) : r[r.length-1] = [...r[r.length-1], c], r), )
console.log(chunkBy(range(1,21,1), 10))
The chunkBy
uses Array.reduce
& the %
operator to chunk
the data.
1
And you wrote a mini lodash :D
– slider
Nov 21 '18 at 0:50
add a comment |
Looking at the ES6 Array.from
documentation you can see a range generator function:
const range = (start, stop, step) => Array.from({ length: (stop -
start) / step }, (_, i) => start + (i * step));
So with that in mind you could generate the range via:
range(1, 21, 1) // account for the 0 with the 21 otherwise you get 1-19
Then all that is missing is the chunk
function:
const range = (start, stop, step) => Array.from({ length: (stop - start) / step }, (_, i) => start + (i * step));
const chunkBy = (arr, by=2) => arr.reduce((r,c,i) => (i%by==0 ? r.push([c]) : r[r.length-1] = [...r[r.length-1], c], r), )
console.log(chunkBy(range(1,21,1), 10))
The chunkBy
uses Array.reduce
& the %
operator to chunk
the data.
1
And you wrote a mini lodash :D
– slider
Nov 21 '18 at 0:50
add a comment |
Looking at the ES6 Array.from
documentation you can see a range generator function:
const range = (start, stop, step) => Array.from({ length: (stop -
start) / step }, (_, i) => start + (i * step));
So with that in mind you could generate the range via:
range(1, 21, 1) // account for the 0 with the 21 otherwise you get 1-19
Then all that is missing is the chunk
function:
const range = (start, stop, step) => Array.from({ length: (stop - start) / step }, (_, i) => start + (i * step));
const chunkBy = (arr, by=2) => arr.reduce((r,c,i) => (i%by==0 ? r.push([c]) : r[r.length-1] = [...r[r.length-1], c], r), )
console.log(chunkBy(range(1,21,1), 10))
The chunkBy
uses Array.reduce
& the %
operator to chunk
the data.
Looking at the ES6 Array.from
documentation you can see a range generator function:
const range = (start, stop, step) => Array.from({ length: (stop -
start) / step }, (_, i) => start + (i * step));
So with that in mind you could generate the range via:
range(1, 21, 1) // account for the 0 with the 21 otherwise you get 1-19
Then all that is missing is the chunk
function:
const range = (start, stop, step) => Array.from({ length: (stop - start) / step }, (_, i) => start + (i * step));
const chunkBy = (arr, by=2) => arr.reduce((r,c,i) => (i%by==0 ? r.push([c]) : r[r.length-1] = [...r[r.length-1], c], r), )
console.log(chunkBy(range(1,21,1), 10))
The chunkBy
uses Array.reduce
& the %
operator to chunk
the data.
const range = (start, stop, step) => Array.from({ length: (stop - start) / step }, (_, i) => start + (i * step));
const chunkBy = (arr, by=2) => arr.reduce((r,c,i) => (i%by==0 ? r.push([c]) : r[r.length-1] = [...r[r.length-1], c], r), )
console.log(chunkBy(range(1,21,1), 10))
const range = (start, stop, step) => Array.from({ length: (stop - start) / step }, (_, i) => start + (i * step));
const chunkBy = (arr, by=2) => arr.reduce((r,c,i) => (i%by==0 ? r.push([c]) : r[r.length-1] = [...r[r.length-1], c], r), )
console.log(chunkBy(range(1,21,1), 10))
edited Nov 21 '18 at 0:47
answered Nov 21 '18 at 0:16


AkrionAkrion
9,42711224
9,42711224
1
And you wrote a mini lodash :D
– slider
Nov 21 '18 at 0:50
add a comment |
1
And you wrote a mini lodash :D
– slider
Nov 21 '18 at 0:50
1
1
And you wrote a mini lodash :D
– slider
Nov 21 '18 at 0:50
And you wrote a mini lodash :D
– slider
Nov 21 '18 at 0:50
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53403334%2fuse-javascript-or-lodash-to-create-multi-dimensional-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What happened when you tried
_.range(20)
? Perhaps you'd then be interested in_.chunk()
– Phil
Nov 20 '18 at 23:54
1
Pure JS:
Array.from(new Array(30)).map((_, i) => i + 1).reduce((acc, v) => v % 10 === 1 ? [...acc, [v]] : (acc[Math.floor((v - 1) / 10)].push(v), acc), )
– zerkms
Nov 20 '18 at 23:58