forked from Automedon/CodeWars-7-kyu-Soluitions-part-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdding Arrays.js
38 lines (31 loc) · 1.27 KB
/
Adding Arrays.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
Create a function that takes an array of letters, and combines them into words in a sentence.
The array will be formatted as so:
[['J','L','L','M']
,['u','i','i','a']
,['s','v','f','n']
,['t','e','e','']]
The function should combine all the 0th indexed letters to create the word 'just', all the 1st indexed letters to create the word 'live', etc.
Shorter words will have an empty string in the place once the word has already been mapped out (see the last element in the last element in the array).
Examples:
arrAdder([
['J','L','L','M'],
['u','i','i','a'],
['s','v','f','n'],
['t','e','e','']
]) // => "Just Live Life Man"
arrAdder([
[ 'T', 'M', 'i', 't', 'p', 'o', 't', 'c' ],
[ 'h', 'i', 's', 'h', 'o', 'f', 'h', 'e' ],
[ 'e', 't', '', 'e', 'w', '', 'e', 'l' ],
[ '', 'o', '', '', 'e', '', '', 'l' ],
[ '', 'c', '', '', 'r', '', '', '' ],
[ '', 'h', '', '', 'h', '', '', '' ],
[ '', 'o', '', '', 'o', '', '', '' ],
[ '', 'n', '', '', 'u', '', '', '' ],
[ '', 'd', '', '', 's', '', '', '' ],
[ '', 'r', '', '', 'e', '', '', '' ],
[ '', 'i', '', '', '', '', '', '' ],
[ '', 'a', '', '', '', '', '', '' ] ]) // => "The Mictochondria is the powerhouse of the cell"
*/
const arrAdder = arr => arr[0].map((_,i)=> arr.map((_,j)=> arr[j][i]).join('')).join(' ');