-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddingArrays.js
More file actions
88 lines (83 loc) · 2.23 KB
/
Copy pathAddingArrays.js
File metadata and controls
88 lines (83 loc) · 2.23 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* Description:
*
* 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:
* [
* ['J','L','L','M'],
* ['u','i','i','a'],
* ['s','v','f','n'],
* ['t','e','e','']
* ] // => "Just Live Life Man"
*
*
* [
* [ '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 Mitochondria is the powerhouse of the cell"
*
* Kata URL: https://www.codewars.com/kata/59778cb1b061e877c50000cc
*
*
* @param {*} arr
*/
function arrAdder(arr) {
let result = "";
for (let j = 0; j < arr[0].length; j++) {
for (let i = 0; i < arr.length; i++) {
result += arr[i][j];
}
result += " ";
}
return result.slice(0, -1);
}
let a = [
["J", "L", "L", "M"],
["u", "i", "i", "a"],
["s", "v", "f", "n"],
["t", "e", "e", ""],
];
let b = [
["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", "", "", "", "", "", ""],
];
console.log(arrAdder(a));
console.log(arrAdder(b));