Answers for "typescript split/partition array by condition"

0

typescript split/partition array by condition

const [small, large] =                             // Use "deconstruction" style assignment
  [12, 5, 8, 130, 44]
    .reduce((result, element) => {
      result[element <= 10 ? 0 : 1].push(element); // Determine and push to small/large arr
      return result;
    },
    [[], []]);                                     // Default small/large arrays are empty
Posted by: Guest on May-17-2021

Code answers related to "typescript split/partition array by condition"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language