-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram_43.ts
33 lines (26 loc) · 1.1 KB
/
program_43.ts
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
/*
* Unchanged Magicians: Start with your work from Exercise 40.
* Call the function make_great() with a copy of the array of magicians’ names.
* Because the original array will be unchanged, return the new array and store it in a separate array.
* Call show_magicians() with each array to show that you have one array of the original
* names and one array with the Great added to each magician’s name.
*/
const magician2: string[] = ["Harry Potter", "Dumbledore", "Snape", "Weasley"];
const greatMagician: string[] = makeGreat2([...magician2]);
function showMagician2(magician2: string[]): void {
for (let magicians of magician2) {
console.log(`- ${magicians}`);
}
}
function makeGreat2(magician2: string[]): string[] {
const modifiedMagician: string[] = [];
for (let i = 0; i < magician2.length; i++) {
modifiedMagician.push("The Great" + " " + magician2[i]);
}
return modifiedMagician;
}
console.log("Harry Potter Movie Magicians \n");
console.log("Original Magician Names:");
showMagician2(magician2);
console.log("\n Great Magician Names:");
showMagician2(greatMagician);