2018-10-10 18:03:03 -04:00
---
id: ab306dbdcc907c7ddfc30830
title: Steamroller
isRequired: true
challengeType: 5
2019-08-28 16:26:13 +03:00
forumTopicId: 16079
2018-10-10 18:03:03 -04:00
localeTitle: пробиваться с боями
---
## Description
2019-08-28 16:26:13 +03:00
< section id = 'description' >
Сгладьте вложенный массив. Вы должны учитывать различные уровни гнездования. Н е забудьте использовать < a href = "http://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514" target = "_blank" > Read-Search-Ask,< / a > если вы застряли. Попробуйте подключить программу. Напишите свой собственный код.
< / section >
2018-10-10 18:03:03 -04:00
## Instructions
2019-08-28 16:26:13 +03:00
< section id = 'instructions' >
2018-10-10 18:03:03 -04:00
< / section >
## Tests
< section id = 'tests' >
```yml
tests:
2019-08-28 16:26:13 +03:00
- text: < code > steamrollArray([[["a"]], [["b"]]])</ code > should return < code > ["a", "b"]</ code > .
testString: assert.deepEqual(steamrollArray([[["a"]], [["b"]]]), ["a", "b"]);
- text: < code > steamrollArray([1, [2], [3, [[4]]]])</ code > should return < code > [1, 2, 3, 4]</ code > .
testString: assert.deepEqual(steamrollArray([1, [2], [3, [[4]]]]), [1, 2, 3, 4]);
- text: < code > steamrollArray([1, [], [3, [[4]]]])</ code > should return < code > [1, 3, 4]</ code > .
testString: assert.deepEqual(steamrollArray([1, [], [3, [[4]]]]), [1, 3, 4]);
- text: < code > steamrollArray([1, {}, [3, [[4]]]])</ code > should return < code > [1, {}, 3, 4]</ code > .
testString: assert.deepEqual(steamrollArray([1, {}, [3, [[4]]]]), [1, {}, 3, 4]);
2018-10-10 18:03:03 -04:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'js-seed' >
```js
function steamrollArray(arr) {
// I'm a steamroller, baby
return arr;
}
steamrollArray([1, [2], [3, [[4]]]]);
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
2019-08-28 16:26:13 +03:00
function steamrollArray(arr) {
if (!Array.isArray(arr)) {
return [arr];
}
var out = [];
arr.forEach(function(e) {
steamrollArray(e).forEach(function(v) {
out.push(v);
});
});
return out;
}
2018-10-10 18:03:03 -04:00
```
2019-08-28 16:26:13 +03:00
2018-10-10 18:03:03 -04:00
< / section >