Master JavaScript
One line, the way console.log writes it
You are writing a small logging helper for a program that has no console of its own, so it has to build the line as text and hand it back. The job is to reproduce exactly what console.log would have written.
You are given a label, which is a piece of text, and values, which is a list of whole numbers. Put the label first, then every number in order, with exactly one space between each pair of parts.
Input: label = "total", values = [1, 2, 3]
Output: "total 1 2 3"
Built one part at a time:
the label -> "total"
a space, then 1 -> "total 1"
a space, then 2 -> "total 1 2"
a space, then 3 -> "total 1 2 3"There is one space between parts, never at either end. That means the two empty cases need care.
Input: label = "count", values = []
Output: "count"
Input: label = "", values = [4, 5]
Output: "4 5"
Input: label = "", values = []
Output: ""label is a piece of text with no spaces at either end. It may be empty.values holds between 0 and 100 whole numbers, each between -1000 and 1000.Run your code to see how it does on the examples. Submit also runs the hidden cases.