Dev Helpers
← Back

Unroll run-length records

Unroll run-length records using JavaScript.

Open this example in the interactive library

Source code

const compressed = [
  ["ink", 3],
  ["paper", 2],
];
console.log(compressed.flatMap(([item, n]) => Array(n).fill(item)));

Sample output

[ 'ink', 'ink', 'ink', 'paper', 'paper' ]