-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day 12
48 lines (37 loc) · 1.31 KB
/
Day 12
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
DAY 12
Instructions
(This challenge is worth 20 points)
Your task is to write a function that will take in an array of objects containing a sender and a message as a parameter. The function will then parse a message from each object, add it to an array then return the built array.
Each message is built exactly like the first challenge, so you can either use the function you already made, or rebuild it from scratch.
Examples
Input:
const messages = [
{origin:"MC", message:"Hello!"},
{origin:"Shuttle", message:"Hey!"},
]
Output:
[
"MC: Hello!",
"Shuttle: Hey!"
]
SOLUTION
function parseMessage(origin, message){
if (typeof origin === 'string' || origin instanceof String) {
origin = origin.replace(/^"|"$/g, '');
} else {
console.log ("Please re-enter the sender's name in a text format.")
return}
if (typeof message === 'string' || message instanceof String) {
message = message.replace(/^"|"$/g, '');
} else {
return "Please re-enter the message in a text format."}
const result = origin + ": " + message;
return result
}
function parseTranscripts(messages){
let arr = [];
for (let i of messages){
let msg = parseMessage(i.origin, i.message);
arr.push(msg);
} return arr;
}