Created
January 28, 2020 15:44
-
-
Save hiwaldo89/0b8802f106a55e022ff0d0d6b766bed0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const characters = [ | |
{ | |
char: "h", | |
position: [0] | |
}, | |
{ | |
char: "e", | |
position: [1] | |
}, | |
{ | |
char: "l", | |
position: [2,3,10] | |
}, | |
{ | |
char: "o", | |
position: [4,8] | |
}, | |
{ | |
char: ",", | |
position: [5] | |
}, | |
{ | |
char: " ", | |
position: [6] | |
}, | |
{ | |
char: "w", | |
position: [7] | |
}, | |
{ | |
char: "r", | |
position: [9] | |
}, | |
{ | |
char: "d", | |
position: [11] | |
}, | |
{ | |
char: "!", | |
position: [12] | |
} | |
] | |
function printHello(characters) { | |
const helloArray = []; | |
characters.forEach(character => { | |
character.position.forEach(position => { | |
helloArray[position] = position === 0 ? character.char.toUpperCase() : character.char; | |
}) | |
}); | |
console.log(helloArray.join("")); | |
} | |
printHello(characters); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment