Basics

Challenges

Classes

Cookies

Debugging

Events

External Files

Flow Control

Forms

Functions

Html Elements

Installation

Interfaces

Keywords

Modules

Namespaces

Operators

Reference Files

String

Types

TypeScript - Equal Division Challenge

Here are three examples of how to take a list and divide them up into 2 buckets as equally as possible. Each test increases in it's complexity.

Which one will do the best job? Watch the developer's console when running the tests. Inspired by Mr. Waffles.

 

 

Alternating

This technique sorts the numbers (desc) and then runs thru the list and alternates between bucket1 and bucket2 inserts it into one or the other.

Equal Split Test

This technique will calculate a break point by dividing the sum of all numbers by 2. It will run thru the numbers list (desc) and insert into bucket1 as long as it hasn't exceeded the breakpoint and then will switch over to bucket 2 once it exceeds the breakpoint.

Top & Bottom Cherry Pick

This technique does the following:

  • sorts the list desc and then picks the very most top value (max) and inserts it into the bucket with the lowest total
  • removes the value just used from the list so it cannot be used again
  • resorts the list in ascending order and grabs the top most (min) value. It will insert this min value into the bucket with the lowest total
  • removes the value just used from the list so it cannot be used again
  • resorts the list again in desc order and starts over