Basics
Challenges
Classes
Debugging
Events
External Files
Flow Control
Forms
Functions
Html Elements
Installation
Interfaces
Keywords
Modules
Namespaces
Operators
Reference Files
String
Types
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.
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.
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.
This technique does the following: