# Khan/khan-exercises

Fetching contributors…
Cannot retrieve contributors at this time
111 lines (103 sloc) 4.57 KB
 Ordering negative numbers
randRangeUnique(-100, 100, randRange(4, 6)) sortNumbers(NUMS)
KhanUtil.shuffle(["blue", "green", "red", "purple", "orange", "brown", "gray", "teal", "olive"]) (function() { var mapping = {}; for (var i = 0; i < NUMS.length; i++) { mapping[NUMS[i]] = COLORS[i]; } return mapping; })() \$.map(NUMS, function(n) { return "\\color{" + NUM_COLORS[n] + "}{" + n + "}"; } ).join( "," ) \$.map(NUMS_SORT, function(n) { return "\\color{" + NUM_COLORS[n] + "}{" + n + "}"; } ).join( "," ) createSorter()

Order the following integers from least to greatest:

• NUM NUM

SORTER.init("sortable")

SORTER.getContent()
if (SORTER.hasAttempted) { return guess.join(",") === NUMS_SORT.join(","); } else { return ""; }
SORTER.setContent(guess);

Let's use different colors for each number.

NUMS_COLOR

Plot these numbers on a number line. Then we can see which ones are lower and which ones are higher.

init({ range: [[-1, 201], [-1, 1]], scale: [2.2, 40] }); style({ stroke: "#666" }, function() { graph.nl = numberLine(-100, 100, 25); });
_.each(graph.nl.labels.slice(1, -1), function(label) { label.remove(); }); var position = "above"; \$.each(NUMS_SORT, function(i, n) { ellipse([100 + n, 0], [1.88, 0.1], { "stroke-width": 0, fill: NUM_COLORS[n] }); label([100 + n, 0], "\\color{" + NUM_COLORS[n] + "}{" + n + "}", position, { labelDistance: 5 }); position = (position === "above" ? "below" : "above"); } );

Now just read the numbers from left to right on the number line.

The leftmost numbers are least, and the rightmost numbers are greatest.

NUMS_SORT_COLOR