← Back to challenges

Index Shuffle

JavaScriptHardstringsloops

Instructions

Write a function that takes all even-indexed characters and odd-indexed characters from a string and concatenates them together.

To illustrate:

indexShuffle("abcd") ➞ "acbd"
// "ac" (even-indexed) + "bd" (odd-indexed)

Examples

indexShuffle("abcdefg") ➞ "acegbdf"

indexShuffle("holiday") ➞ "hldyoia"

indexShuffle("maybe") ➞ "myeab"

Notes

0 should be treated as an even number.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Chat Room Status