Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

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
Source by codereview.stackexchange.com #
 
PREVIOUS NEXT
Tagged: #typescript #array #condition
ADD COMMENT
Topic
Name
7+9 =