← Back to challenges

Recreate C#'s String.Format

JavaScriptHardformattingstrings

Instructions

Recreate C#'s String.Format where the first argument is the string template and all subsequent arguments are the values for the corresponding placeholders in the template.

Examples

String.Format("{0}{1}{2}{1}{0}",  "k",  "a", "y") ➞ "kayak"

String.Format("Palindromes are {0}", "fun") ➞ "Palindromes are fun"

String.Format("Hello {0}.\nGeneral {1}",  "there",  "Kenobi") ➞ "Hello there.\nGeneral Kenobi"

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.