Trying to solve this puzzle in JavaScript:
Input: An array containing x amoung of arrays of numbers. Heres example:
[
[1,4],
[6,8],
[10]
]
Expected Output: I would want to run some sort of code to turn it into:
1-4,6-8,10
I've tried join("-") and tried the same thing within a forEach() loop but can't quite get it to work
You can use map the array and join each item by a dash, then join the resulting array.
const arr = [
[1, 4],
[6, 8],
[10]
]
const res = arr.map(e => e.join('-')).join()
console.log(res)