DEV Community

Bobokhon Rajabov
Bobokhon Rajabov

Posted on

Flatten and sort an array 7 Kyu

function flattenAndSort(array) {
  return   array.flat().sort((a, b) => a - b);
}

//answer [1, 2, 3, 4, 5,6, 7, 8,9]
Enter fullscreen mode Exit fullscreen mode

The flat() method creates a new array with sub-array elements concatenated to a specified depth and I am using sort() method for order sequence.

Top comments (0)