# Khan/khan-exercises

Fetching contributors…
Cannot retrieve contributors at this time
186 lines (174 sloc) 8.52 KB
 Comparing objects
randFromArray(["square", "circle", "triangle"]) shuffle([4, 5.2, 6.4, 7.6, 8.8, 10], 4) shuffle(["#aec6f4", "#fdcf76", "#8ed4b8", "#fd79d4"]) {}

Which SHAPE is the QUESTION?

init({ range: [[0, 100], [-11, 11]], scale: [5, 5] }); var x = 0; DRAW.square = function(x, y, size, color) { KhanUtil.currentGraph.path([[x - size, y + size], [x + size, y + size], [x + size, y - size], [x - size, y - size], true], { strokeWidth: 2, stroke: "black", fill: color }); }; DRAW.circle = function(x, y, size, color) { KhanUtil.currentGraph.circle([x, y], size, { strokeWidth: 2, stroke: "black", fill: color }); }; DRAW.triangle = function(x, y, size, color) { KhanUtil.currentGraph.path([[x, y + size], [x + (2 * size) / sqrt(3), y - size / sqrt(3)], [x - (2 * size) / sqrt(3), y - size / sqrt(3)], true ], { strokeWidth: 2, stroke: "black", fill: color }); }; _(4).times(function(i) { x += SIZES[i] + 5; DRAW[SHAPE](x, 0, SIZES[i], COLORS[i]); label([x, 0], "ABCD"[i]); x += SIZES[i]; });

capitalize(SHAPE) SOLUTION

• capitalize(SHAPE) A
• capitalize(SHAPE) B
• capitalize(SHAPE) C
• capitalize(SHAPE) D
"biggest" "ABCD"[_.indexOf(SIZES, _.max(SIZES))] (function() { var l = []; for (var i = 1; i < 4; i++) { var first = l.length ? l[l.length - 1].larger : 0; var second = i; var larger = _.max([first, second], function(i) { return SIZES[i]; }); var smaller = _.min([first, second], function(i) { return SIZES[i]; }); l.push({ first: first, second: second, larger: larger, smaller: smaller }); } return l; })()

Bigger things take up more space.

Which SHAPE takes up the most space?

Which takes up more space? capitalize(SHAPE) "ABCD"[COMP.first] or SHAPE "ABCD"[COMP.second]?

init({ range: [[-11, 16], [-11, 11]], scale: [5, 5] }); DRAW[SHAPE](0, 0, SIZES[COMP.larger], COLORS[COMP.larger]); DRAW[SHAPE](0, 0, SIZES[COMP.smaller], COLORS[COMP.smaller]); label([0, 0], "ABCD"[COMP.smaller]); label([SIZES[COMP.larger] + 2, 0], "ABCD"[COMP.larger]);

We can move SHAPE "ABCD"[COMP.smaller] inside SHAPE "ABCD"[COMP.larger], so SHAPE "ABCD"[COMP.larger] is bigger than SHAPE "ABCD"[COMP.smaller].

init({ range: [[-11, 16], [-11, 11]], scale: [5, 5] }); _.each(sortNumbers(SIZES).reverse(), function(size) { DRAW[SHAPE](0, 0, size, COLORS[_.indexOf(SIZES, size)]); }); label([_.max(SIZES) + 2, 0], SOLUTION);

capitalize(SHAPE) SOLUTION is the biggest.

"smallest" "ABCD"[_.indexOf(SIZES, _.min(SIZES))] (function() { var l = []; for (var i = 1; i < 4; i++) { var first = l.length ? l[l.length - 1].smaller : 0; var second = i; var larger = _.max([first, second], function(i) { return SIZES[i]; }); var smaller = _.min([first, second], function(i) { return SIZES[i]; }); l.push({ first: first, second: second, larger: larger, smaller: smaller }); } return l; })()

Smaller things take up less space.

Which SHAPE takes up the least space?

Which takes up less space? capitalize(SHAPE) "ABCD"[COMP.first] or SHAPE "ABCD"[COMP.second]?

init({ range: [[-11, 16], [-11, 11]], scale: [5, 5] }); DRAW[SHAPE](0, 0, SIZES[COMP.larger], COLORS[COMP.larger]); DRAW[SHAPE](0, 0, SIZES[COMP.smaller], COLORS[COMP.smaller]); label([0, 0], "ABCD"[COMP.smaller]);

We can move SHAPE "ABCD"[COMP.smaller] inside SHAPE "ABCD"[COMP.larger], so SHAPE "ABCD"[COMP.smaller] is smaller than SHAPE "ABCD"[COMP.larger].

init({ range: [[-11, 16], [-11, 11]], scale: [5, 5] }); _.each(sortNumbers(SIZES).reverse(), function(size) { DRAW[SHAPE](0, 0, size, COLORS[_.indexOf(SIZES, size)]); }); label([0, 0], SOLUTION);

capitalize(SHAPE) SOLUTION is the smallest.

Something went wrong with that request. Please try again.