Coding/Blog challenge 9

Coding/Blog challenge 9

Today's challenge is brought to you by Edabit. I wanted to look at other places to get challenges from, just for giggles. I actually like the site because it's easier to set your preferences for different difficulty levels. There are also tutorials and other resources.

Up until this point, I have been finding a challenge, completing it and then blogging it. This time I am starting the blog just after I've read the challenge to make the dynamic a bit different.

Gladiator's Ring

JsProblem9.png

At first glance, it took me a second to think about this, specifically because of the 3rd example that they give. They also provided a dead giveaway by saying to use the spread syntax. The instructions also state that the first array passed will always have two elements. So what I am thinking is: If we simply just return array1 at zero index, spread array2 & finally array1's second element(at index 1) all wrapped in an array. Simple as that.

Solution

This was in their intermediate section, but it was really simple, next time I'll up the difficulty level. Here's the code:

function tuckIn(arr1, arr2) {
    return [ arr1[0], ...arr2, arr1[1] ]
}

The spread operator is a pretty nifty tool to have in the arsenal, don't you think?