Skip to content

Commit db3aa5d

Browse files
committed
flatten()
1 parent 4b47e32 commit db3aa5d

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ My Codewars solutions in various languages.
2222
- [Arguments to Binary addition (8 kyu)](https://www.codewars.com/kata/arguments-to-binary-addition) [[solution](https://github.com/PaulNoth/codewars/blob/master/arguments-to-binary-addition/solution.md)] [[javascript](https://github.com/PaulNoth/codewars/blob/master/arguments-to-binary-addition/kata.js)]
2323
- [Mr. Freeze (8 kyu)](https://www.codewars.com/kata/mr-freeze) [[solution](https://github.com/PaulNoth/codewars/blob/master/mr-freeze/solution.md)] [[javascript](https://github.com/PaulNoth/codewars/blob/master/mr-freeze/kata.js)]
2424
- [RGB To Hex Conversion (5 kyu)](https://www.codewars.com/kata/rgb-to-hex-conversion) [[solution](https://github.com/PaulNoth/codewars/blob/master/rgb-to-hex-conversion/solution.md)] [[javascript](https://github.com/PaulNoth/codewars/blob/master/rgb-to-hex-conversion/kata.js)]
25+
- [flatten (5 kyu)](https://www.codewars.com/kata/flatten) [[solution](https://github.com/PaulNoth/codewars/blob/master/flatten/solution.md)] [[javascript](https://github.com/PaulNoth/flatten/blob/master/rgb-to-hex-conversion/kata.js)]

Diff for: flatten/kata.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function flatten() {
2+
let elements = [];
3+
const args = [...arguments];
4+
5+
for(let i = 0; i < args.length; i++) {
6+
const arg = args[i];
7+
if(arg && arg.constructor === Array) {
8+
elements = elements.concat(flatten(...arg));
9+
} else {
10+
elements.push(arg);
11+
}
12+
}
13+
return elements;
14+
}

Diff for: flatten/solution.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### flatten()
2+
3+
Loot at the solution.

0 commit comments

Comments
 (0)