How can I return a different array?
I need to return an array consisting of the largest number from each provided sub-array. So, I've written the following code and it works but I have:
[[25],[48],[21],[-3]]
instead of [25,48,21,-3]
. Can I change something to get the right answer?
function largestOfFour(arr) {
for (let i = 0; i < arr.length; i++) {
arr[i].sort(function(a,b) {
return b - a;
}).map(function() {
return arr[i].splice(1);
})
}
return arr;
}
var result = largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]);
console.log(result);
javascript
add a comment |
I need to return an array consisting of the largest number from each provided sub-array. So, I've written the following code and it works but I have:
[[25],[48],[21],[-3]]
instead of [25,48,21,-3]
. Can I change something to get the right answer?
function largestOfFour(arr) {
for (let i = 0; i < arr.length; i++) {
arr[i].sort(function(a,b) {
return b - a;
}).map(function() {
return arr[i].splice(1);
})
}
return arr;
}
var result = largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]);
console.log(result);
javascript
One way is that you can flatten it!
– choz
Jan 2 at 13:10
add a comment |
I need to return an array consisting of the largest number from each provided sub-array. So, I've written the following code and it works but I have:
[[25],[48],[21],[-3]]
instead of [25,48,21,-3]
. Can I change something to get the right answer?
function largestOfFour(arr) {
for (let i = 0; i < arr.length; i++) {
arr[i].sort(function(a,b) {
return b - a;
}).map(function() {
return arr[i].splice(1);
})
}
return arr;
}
var result = largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]);
console.log(result);
javascript
I need to return an array consisting of the largest number from each provided sub-array. So, I've written the following code and it works but I have:
[[25],[48],[21],[-3]]
instead of [25,48,21,-3]
. Can I change something to get the right answer?
function largestOfFour(arr) {
for (let i = 0; i < arr.length; i++) {
arr[i].sort(function(a,b) {
return b - a;
}).map(function() {
return arr[i].splice(1);
})
}
return arr;
}
var result = largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]);
console.log(result);
function largestOfFour(arr) {
for (let i = 0; i < arr.length; i++) {
arr[i].sort(function(a,b) {
return b - a;
}).map(function() {
return arr[i].splice(1);
})
}
return arr;
}
var result = largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]);
console.log(result);
function largestOfFour(arr) {
for (let i = 0; i < arr.length; i++) {
arr[i].sort(function(a,b) {
return b - a;
}).map(function() {
return arr[i].splice(1);
})
}
return arr;
}
var result = largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]);
console.log(result);
javascript
javascript
edited Jan 2 at 14:45
Armel
1,206920
1,206920
asked Jan 2 at 13:08


Ilya SolodeevIlya Solodeev
33
33
One way is that you can flatten it!
– choz
Jan 2 at 13:10
add a comment |
One way is that you can flatten it!
– choz
Jan 2 at 13:10
One way is that you can flatten it!
– choz
Jan 2 at 13:10
One way is that you can flatten it!
– choz
Jan 2 at 13:10
add a comment |
6 Answers
6
active
oldest
votes
Loop and sort, then return the first element of each sub-array with map
;
function largestOfFour(arr) {
for (let i = 0; i < arr.length; i++) {
arr[i].sort(function(a,b) {
return b - a;
});
}
return arr.map(array => array[0]);
}
Better still, do it in one.
function largestOfFour(arr) {
return arr.map(array => array.sort((a,b) => b - a)[0]);
}
1
Better still, useMath.max
instead ofsort
.
– str
Jan 2 at 13:38
add a comment |
You could use map
with spread syntax ...
to return 1D array as pointed out by @str .
function largestOfFour(arr) {
return arr.map(a => Math.max(...a))
}
const arr = [[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]
const result = largestOfFour(arr);
console.log(result)
You could also use reduce
function largestOfFour(arr) {
return arr.reduce((r, a) => r.concat(Math.max(...a)), )
}
const arr = [[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]
const result = largestOfFour(arr);
console.log(result)
3
concat
is not even needed,arr.map(a => Math.max(...a))
is enough.
– str
Jan 2 at 13:15
return arr.map(function(a) { return Math.max.apply(Math, a); });
If you need to support IE
– freddyrobinson
Jan 2 at 13:19
add a comment |
get the first character of each array using [0]
index like this
function largestOfFour(arr) {
for (let i = 0; i < arr.length; i++) {
arr[i].sort(function(a,b) {
return b - a;
}).map(function() {
// HERE
return arr[i].splice(1)[0];
})
}
return arr;
}
largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]);
add a comment |
You could map the first element of the descending sorted elements.
function largestOfFour(array) {
return array.map(a => a.sort((a, b) => b - a)[0]);
}
console.log(largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]));
add a comment |
You can use map
which will return a new array and then use Math.max
to get the maximum value form the array
function largestOfFour(arr) {
return arr.map(item => {
return [Math.max.apply(null, item)]
})
}
console.log(largestOfFour([
[17, 23, 25, 12],
[25, 7, 34, 48],
[4, -10, 18, 21],
[-72, -3, -17, -10]
]));
add a comment |
you can use flat function for it
var arr1 = [1, 2, [3, 4]];
arr1.flat();
// [1, 2, 3, 4]
var arr2 = [1, 2, [3, 4, [5, 6]]];
arr2.flat();
// [1, 2, 3, 4, [5, 6]]
var arr3 = [1, 2, [3, 4, [5, 6]]];
arr3.flat(2);
// [1, 2, 3, 4, 5, 6]
1
It's always better to mention the source of our answers: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
– Armel
Jan 2 at 13:14
1
Note that this is not supported in IE or Edge
– freddyrobinson
Jan 2 at 13:15
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%2f54006957%2fhow-can-i-return-a-different-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
Loop and sort, then return the first element of each sub-array with map
;
function largestOfFour(arr) {
for (let i = 0; i < arr.length; i++) {
arr[i].sort(function(a,b) {
return b - a;
});
}
return arr.map(array => array[0]);
}
Better still, do it in one.
function largestOfFour(arr) {
return arr.map(array => array.sort((a,b) => b - a)[0]);
}
1
Better still, useMath.max
instead ofsort
.
– str
Jan 2 at 13:38
add a comment |
Loop and sort, then return the first element of each sub-array with map
;
function largestOfFour(arr) {
for (let i = 0; i < arr.length; i++) {
arr[i].sort(function(a,b) {
return b - a;
});
}
return arr.map(array => array[0]);
}
Better still, do it in one.
function largestOfFour(arr) {
return arr.map(array => array.sort((a,b) => b - a)[0]);
}
1
Better still, useMath.max
instead ofsort
.
– str
Jan 2 at 13:38
add a comment |
Loop and sort, then return the first element of each sub-array with map
;
function largestOfFour(arr) {
for (let i = 0; i < arr.length; i++) {
arr[i].sort(function(a,b) {
return b - a;
});
}
return arr.map(array => array[0]);
}
Better still, do it in one.
function largestOfFour(arr) {
return arr.map(array => array.sort((a,b) => b - a)[0]);
}
Loop and sort, then return the first element of each sub-array with map
;
function largestOfFour(arr) {
for (let i = 0; i < arr.length; i++) {
arr[i].sort(function(a,b) {
return b - a;
});
}
return arr.map(array => array[0]);
}
Better still, do it in one.
function largestOfFour(arr) {
return arr.map(array => array.sort((a,b) => b - a)[0]);
}
answered Jan 2 at 13:14


prettyflyprettyfly
1,23611021
1,23611021
1
Better still, useMath.max
instead ofsort
.
– str
Jan 2 at 13:38
add a comment |
1
Better still, useMath.max
instead ofsort
.
– str
Jan 2 at 13:38
1
1
Better still, use
Math.max
instead of sort
.– str
Jan 2 at 13:38
Better still, use
Math.max
instead of sort
.– str
Jan 2 at 13:38
add a comment |
You could use map
with spread syntax ...
to return 1D array as pointed out by @str .
function largestOfFour(arr) {
return arr.map(a => Math.max(...a))
}
const arr = [[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]
const result = largestOfFour(arr);
console.log(result)
You could also use reduce
function largestOfFour(arr) {
return arr.reduce((r, a) => r.concat(Math.max(...a)), )
}
const arr = [[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]
const result = largestOfFour(arr);
console.log(result)
3
concat
is not even needed,arr.map(a => Math.max(...a))
is enough.
– str
Jan 2 at 13:15
return arr.map(function(a) { return Math.max.apply(Math, a); });
If you need to support IE
– freddyrobinson
Jan 2 at 13:19
add a comment |
You could use map
with spread syntax ...
to return 1D array as pointed out by @str .
function largestOfFour(arr) {
return arr.map(a => Math.max(...a))
}
const arr = [[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]
const result = largestOfFour(arr);
console.log(result)
You could also use reduce
function largestOfFour(arr) {
return arr.reduce((r, a) => r.concat(Math.max(...a)), )
}
const arr = [[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]
const result = largestOfFour(arr);
console.log(result)
3
concat
is not even needed,arr.map(a => Math.max(...a))
is enough.
– str
Jan 2 at 13:15
return arr.map(function(a) { return Math.max.apply(Math, a); });
If you need to support IE
– freddyrobinson
Jan 2 at 13:19
add a comment |
You could use map
with spread syntax ...
to return 1D array as pointed out by @str .
function largestOfFour(arr) {
return arr.map(a => Math.max(...a))
}
const arr = [[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]
const result = largestOfFour(arr);
console.log(result)
You could also use reduce
function largestOfFour(arr) {
return arr.reduce((r, a) => r.concat(Math.max(...a)), )
}
const arr = [[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]
const result = largestOfFour(arr);
console.log(result)
You could use map
with spread syntax ...
to return 1D array as pointed out by @str .
function largestOfFour(arr) {
return arr.map(a => Math.max(...a))
}
const arr = [[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]
const result = largestOfFour(arr);
console.log(result)
You could also use reduce
function largestOfFour(arr) {
return arr.reduce((r, a) => r.concat(Math.max(...a)), )
}
const arr = [[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]
const result = largestOfFour(arr);
console.log(result)
function largestOfFour(arr) {
return arr.map(a => Math.max(...a))
}
const arr = [[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]
const result = largestOfFour(arr);
console.log(result)
function largestOfFour(arr) {
return arr.map(a => Math.max(...a))
}
const arr = [[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]
const result = largestOfFour(arr);
console.log(result)
function largestOfFour(arr) {
return arr.reduce((r, a) => r.concat(Math.max(...a)), )
}
const arr = [[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]
const result = largestOfFour(arr);
console.log(result)
function largestOfFour(arr) {
return arr.reduce((r, a) => r.concat(Math.max(...a)), )
}
const arr = [[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]
const result = largestOfFour(arr);
console.log(result)
edited Jan 2 at 13:18
answered Jan 2 at 13:13


Nenad VracarNenad Vracar
72.8k126083
72.8k126083
3
concat
is not even needed,arr.map(a => Math.max(...a))
is enough.
– str
Jan 2 at 13:15
return arr.map(function(a) { return Math.max.apply(Math, a); });
If you need to support IE
– freddyrobinson
Jan 2 at 13:19
add a comment |
3
concat
is not even needed,arr.map(a => Math.max(...a))
is enough.
– str
Jan 2 at 13:15
return arr.map(function(a) { return Math.max.apply(Math, a); });
If you need to support IE
– freddyrobinson
Jan 2 at 13:19
3
3
concat
is not even needed, arr.map(a => Math.max(...a))
is enough.– str
Jan 2 at 13:15
concat
is not even needed, arr.map(a => Math.max(...a))
is enough.– str
Jan 2 at 13:15
return arr.map(function(a) { return Math.max.apply(Math, a); });
If you need to support IE– freddyrobinson
Jan 2 at 13:19
return arr.map(function(a) { return Math.max.apply(Math, a); });
If you need to support IE– freddyrobinson
Jan 2 at 13:19
add a comment |
get the first character of each array using [0]
index like this
function largestOfFour(arr) {
for (let i = 0; i < arr.length; i++) {
arr[i].sort(function(a,b) {
return b - a;
}).map(function() {
// HERE
return arr[i].splice(1)[0];
})
}
return arr;
}
largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]);
add a comment |
get the first character of each array using [0]
index like this
function largestOfFour(arr) {
for (let i = 0; i < arr.length; i++) {
arr[i].sort(function(a,b) {
return b - a;
}).map(function() {
// HERE
return arr[i].splice(1)[0];
})
}
return arr;
}
largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]);
add a comment |
get the first character of each array using [0]
index like this
function largestOfFour(arr) {
for (let i = 0; i < arr.length; i++) {
arr[i].sort(function(a,b) {
return b - a;
}).map(function() {
// HERE
return arr[i].splice(1)[0];
})
}
return arr;
}
largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]);
get the first character of each array using [0]
index like this
function largestOfFour(arr) {
for (let i = 0; i < arr.length; i++) {
arr[i].sort(function(a,b) {
return b - a;
}).map(function() {
// HERE
return arr[i].splice(1)[0];
})
}
return arr;
}
largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]);
answered Jan 2 at 13:12
Joey GoughJoey Gough
744419
744419
add a comment |
add a comment |
You could map the first element of the descending sorted elements.
function largestOfFour(array) {
return array.map(a => a.sort((a, b) => b - a)[0]);
}
console.log(largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]));
add a comment |
You could map the first element of the descending sorted elements.
function largestOfFour(array) {
return array.map(a => a.sort((a, b) => b - a)[0]);
}
console.log(largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]));
add a comment |
You could map the first element of the descending sorted elements.
function largestOfFour(array) {
return array.map(a => a.sort((a, b) => b - a)[0]);
}
console.log(largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]));
You could map the first element of the descending sorted elements.
function largestOfFour(array) {
return array.map(a => a.sort((a, b) => b - a)[0]);
}
console.log(largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]));
function largestOfFour(array) {
return array.map(a => a.sort((a, b) => b - a)[0]);
}
console.log(largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]));
function largestOfFour(array) {
return array.map(a => a.sort((a, b) => b - a)[0]);
}
console.log(largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]));
answered Jan 2 at 13:14


Nina ScholzNina Scholz
193k15106177
193k15106177
add a comment |
add a comment |
You can use map
which will return a new array and then use Math.max
to get the maximum value form the array
function largestOfFour(arr) {
return arr.map(item => {
return [Math.max.apply(null, item)]
})
}
console.log(largestOfFour([
[17, 23, 25, 12],
[25, 7, 34, 48],
[4, -10, 18, 21],
[-72, -3, -17, -10]
]));
add a comment |
You can use map
which will return a new array and then use Math.max
to get the maximum value form the array
function largestOfFour(arr) {
return arr.map(item => {
return [Math.max.apply(null, item)]
})
}
console.log(largestOfFour([
[17, 23, 25, 12],
[25, 7, 34, 48],
[4, -10, 18, 21],
[-72, -3, -17, -10]
]));
add a comment |
You can use map
which will return a new array and then use Math.max
to get the maximum value form the array
function largestOfFour(arr) {
return arr.map(item => {
return [Math.max.apply(null, item)]
})
}
console.log(largestOfFour([
[17, 23, 25, 12],
[25, 7, 34, 48],
[4, -10, 18, 21],
[-72, -3, -17, -10]
]));
You can use map
which will return a new array and then use Math.max
to get the maximum value form the array
function largestOfFour(arr) {
return arr.map(item => {
return [Math.max.apply(null, item)]
})
}
console.log(largestOfFour([
[17, 23, 25, 12],
[25, 7, 34, 48],
[4, -10, 18, 21],
[-72, -3, -17, -10]
]));
function largestOfFour(arr) {
return arr.map(item => {
return [Math.max.apply(null, item)]
})
}
console.log(largestOfFour([
[17, 23, 25, 12],
[25, 7, 34, 48],
[4, -10, 18, 21],
[-72, -3, -17, -10]
]));
function largestOfFour(arr) {
return arr.map(item => {
return [Math.max.apply(null, item)]
})
}
console.log(largestOfFour([
[17, 23, 25, 12],
[25, 7, 34, 48],
[4, -10, 18, 21],
[-72, -3, -17, -10]
]));
answered Jan 2 at 13:16
brkbrk
29.1k32243
29.1k32243
add a comment |
add a comment |
you can use flat function for it
var arr1 = [1, 2, [3, 4]];
arr1.flat();
// [1, 2, 3, 4]
var arr2 = [1, 2, [3, 4, [5, 6]]];
arr2.flat();
// [1, 2, 3, 4, [5, 6]]
var arr3 = [1, 2, [3, 4, [5, 6]]];
arr3.flat(2);
// [1, 2, 3, 4, 5, 6]
1
It's always better to mention the source of our answers: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
– Armel
Jan 2 at 13:14
1
Note that this is not supported in IE or Edge
– freddyrobinson
Jan 2 at 13:15
add a comment |
you can use flat function for it
var arr1 = [1, 2, [3, 4]];
arr1.flat();
// [1, 2, 3, 4]
var arr2 = [1, 2, [3, 4, [5, 6]]];
arr2.flat();
// [1, 2, 3, 4, [5, 6]]
var arr3 = [1, 2, [3, 4, [5, 6]]];
arr3.flat(2);
// [1, 2, 3, 4, 5, 6]
1
It's always better to mention the source of our answers: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
– Armel
Jan 2 at 13:14
1
Note that this is not supported in IE or Edge
– freddyrobinson
Jan 2 at 13:15
add a comment |
you can use flat function for it
var arr1 = [1, 2, [3, 4]];
arr1.flat();
// [1, 2, 3, 4]
var arr2 = [1, 2, [3, 4, [5, 6]]];
arr2.flat();
// [1, 2, 3, 4, [5, 6]]
var arr3 = [1, 2, [3, 4, [5, 6]]];
arr3.flat(2);
// [1, 2, 3, 4, 5, 6]
you can use flat function for it
var arr1 = [1, 2, [3, 4]];
arr1.flat();
// [1, 2, 3, 4]
var arr2 = [1, 2, [3, 4, [5, 6]]];
arr2.flat();
// [1, 2, 3, 4, [5, 6]]
var arr3 = [1, 2, [3, 4, [5, 6]]];
arr3.flat(2);
// [1, 2, 3, 4, 5, 6]
answered Jan 2 at 13:11
stackoverflowstackoverflow
506
506
1
It's always better to mention the source of our answers: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
– Armel
Jan 2 at 13:14
1
Note that this is not supported in IE or Edge
– freddyrobinson
Jan 2 at 13:15
add a comment |
1
It's always better to mention the source of our answers: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
– Armel
Jan 2 at 13:14
1
Note that this is not supported in IE or Edge
– freddyrobinson
Jan 2 at 13:15
1
1
It's always better to mention the source of our answers: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
– Armel
Jan 2 at 13:14
It's always better to mention the source of our answers: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
– Armel
Jan 2 at 13:14
1
1
Note that this is not supported in IE or Edge
– freddyrobinson
Jan 2 at 13:15
Note that this is not supported in IE or Edge
– freddyrobinson
Jan 2 at 13:15
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%2f54006957%2fhow-can-i-return-a-different-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
One way is that you can flatten it!
– choz
Jan 2 at 13:10