* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
1.3 KiB
1.3 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
ab306dbdcc907c7ddfc30830 | Steamroller | 5 | 16079 | steamroller |
--description--
Flatten a nested array. You must account for varying levels of nesting.
--hints--
steamrollArray([[["a"]], [["b"]]])
should return ["a", "b"]
.
assert.deepEqual(steamrollArray([[['a']], [['b']]]), ['a', 'b']);
steamrollArray([1, [2], [3, [[4]]]])
should return [1, 2, 3, 4]
.
assert.deepEqual(steamrollArray([1, [2], [3, [[4]]]]), [1, 2, 3, 4]);
steamrollArray([1, [], [3, [[4]]]])
should return [1, 3, 4]
.
assert.deepEqual(steamrollArray([1, [], [3, [[4]]]]), [1, 3, 4]);
steamrollArray([1, {}, [3, [[4]]]])
should return [1, {}, 3, 4]
.
assert.deepEqual(steamrollArray([1, {}, [3, [[4]]]]), [1, {}, 3, 4]);
Your solution should not use the Array.prototype.flat()
or Array.prototype.flatMap()
methods.
assert(!code.match(/\.\s*flat\s*\(/) && !code.match(/\.\s*flatMap\s*\(/));
--seed--
--seed-contents--
function steamrollArray(arr) {
return arr;
}
steamrollArray([1, [2], [3, [[4]]]]);
--solutions--
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;
}