Skip to content

Instantly share code, notes, and snippets.

@hiwaldo89
Created January 28, 2020 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiwaldo89/0b8802f106a55e022ff0d0d6b766bed0 to your computer and use it in GitHub Desktop.
Save hiwaldo89/0b8802f106a55e022ff0d0d6b766bed0 to your computer and use it in GitHub Desktop.
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