# Khan/khan-exercises

Switch branches/tags
Nothing to show
Fetching contributors…
Cannot retrieve contributors at this time
56 lines (53 sloc) 2.1 KB
 Finding absolute values
rand(5) > 0 ? randRange( 1, 9 ) : 0 rand(3) > 0 ? "." + randRange(1, 9) : "" randFromArray(["", "-"]) Number(SIGN + INT + FRAC) abs(NUMBER)

What is \lvert commafy(NUMBER) \rvert?

ABSOLUTE_NUMBER
init({ range: [ [-1, 11], [-1, 1] ] }); var start = 0; var end = 10; var originX = 0; var x = ABSOLUTE_NUMBER; if ( SIGN === "-" ) { start = -10; end = 0; originX = 10; x = 10 - x; } numberLine( start, end ); style({ stroke: BLUE, fill: BLUE }); graph.pt = circle( [ x, 0 ], 0.15 ); style({ stroke: ORANGE, fill: ORANGE, strokeWidth: 3.5, arrows: "->" }); path( [ [ originX, 0 ], [ x, 0 ] ] ); circle( [ originX, 0 ], 0.10 ); graph.pt.toFront();

The distance from 0 to commafy(NUMBER) is commafy(ABSOLUTE_NUMBER), which equals the absolute value.

In other words, commafy(ABSOLUTE_NUMBER) is the non-negative version of commafy(NUMBER).