-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathframed-reflection.js
More file actions
36 lines (28 loc) · 887 Bytes
/
framed-reflection.js
File metadata and controls
36 lines (28 loc) · 887 Bytes
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
/*
100th Kata
You are given a message (text) that you choose to read in a mirror (weirdo). Return what you would see, complete with the mirror frame. Example:
'Hello World'
would give:
Words in your solution should be left-aligned.
*/
function mirror(text){
let arrText = text.split(' ')
let stringResp = ''
const maxLength = arrText.reduce((acc, cur) => acc.length > cur.length ? acc : cur, '')
console.log(maxLength.length)
for (let j = 0; j < maxLength.length + 4; j++){
stringResp += '*'
}
stringResp += '\n'
for(let i = 0; i < arrText.length; i++){
stringResp += '* ' + arrText[i].split("").reverse().join("")
for (let f = 0; f < maxLength.length - arrText[i].length + 1; f++){
stringResp += ' '
}
stringResp += '*\n'
}
for (let k = 0; k < maxLength.length + 4; k++){
stringResp += '*'
}
return stringResp
}