Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
Merge pull request #12702 from spicyj/commas
Browse files Browse the repository at this point in the history
"Smarter" comma checking
  • Loading branch information
beneater committed Feb 8, 2012
2 parents 0dac5fb + b3fdf66 commit 319a939
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions utils/answer-types.js
Expand Up @@ -51,7 +51,7 @@ jQuery.extend( Khan.answerTypes, {
graphic: function( solutionarea, solution, fallback ) {
var verifier = function( correct, guess ){
return Math.abs( correct - guess ) < 0.3;
}
};
return Khan.answerTypes.text( solutionarea, solution, fallback, verifier );
},

Expand Down Expand Up @@ -311,15 +311,12 @@ jQuery.extend( Khan.answerTypes, {
// Remove space after +, -
.replace( /([+-])\s+/g, "$1" )

// Remove commas
.replace( /,\s*/g, "" )

// Extract integer, numerator and denominator
// This matches [+-]?\.; will f
.match( /^([+-]?(?:\d+\.?|\d*\.\d+))$/ );
// If commas or spaces are used, they must be in the "correct" places
.match( /^([+-]?(?:\d{1,3}(?:[, ]?\d{3})*\.?|\d{0,3}(?:[, ]?\d{3})*\.(?:\d{3}[, ]?)*\d{1,3}))$/ );

if ( match ) {
var x = parseFloat( match[1] );
var x = parseFloat( match[1].replace( /[, ]/g, "" ) );

if ( options.inexact === undefined ) {
var factor = Math.pow( 10, 10 );
Expand Down

0 comments on commit 319a939

Please sign in to comment.