polynomial.js
function(x) {

    var ret = {};

    if (x === null || x === undefined) {
      x = 0;
    }

    switch (typeof x) {

      case "object":

        if (x['coeff']) {
          x = x['coeff'];
        }

        if (Fraction && x instanceof Fraction || Complex && x instanceof Complex || Quaternion && x instanceof Quaternion) {
          ret[0] = x;
        } else
          // Handles Arrays the same way
          for (var i in x) {

            if (!FIELD['empty'](x[i])) {
              ret[i] = FIELD['parse'](x[i]);
            }
          }
        return ret;

      case  "number":
        return {'0': FIELD['parse'](x)};

      case "string":

        var tmp;

        while (null !== (tmp = STR_REGEXP['exec'](x))) {

          var num = 1;
          var exp = 1;

          if (tmp[4] !== undefined) {
            num = tmp[4];
            exp = 0;
          } else if (tmp[2] !== undefined) {
            num = tmp[2];
          }

          num = parseExp(tmp[1], num);

          // Parse exponent
          if (tmp[3] !== undefined) {
            exp = parseInt(tmp[3], 10);
          }

          if (ret[exp] === undefined) {
            ret[exp] = num;
          } else {
            ret[exp] = FIELD['add'](ret[exp], num);
          }
        }
        return ret;
    }
    throw "Invalid Param";
  }
function(x) {

    var ret = {};

    if (x === null || x === undefined) {
      x = 0;
    }

    switch (typeof x) {

      case "object":

        if (x['coeff']) {
          x = x['coeff'];
        }

        if (Fraction && x instanceof Fraction || Complex && x instanceof Complex || Quaternion && x instanceof Quaternion) {
          ret[0] = x;
        } else
          // Handles Arrays the same way
          for (var i in x) {

            if (!FIELD['empty'](x[i])) {
              ret[i] = FIELD['parse'](x[i]);
            }
          }
        return ret;

      case  "number":
        return {'0': FIELD['parse'](x)};

      case "string":

        var tmp;

        while (null !== (tmp = STR_REGEXP['exec'](x))) {

          var num = 1;
          var exp = 1;

          if (tmp[4] !== undefined) {
            num = tmp[4];
            exp = 0;
          } else if (tmp[2] !== undefined) {
            num = tmp[2];
          }

          num = parseExp(tmp[1], num);

          // Parse exponent
          if (tmp[3] !== undefined) {
            exp = parseInt(tmp[3], 10);
          }

          if (ret[exp] === undefined) {
            ret[exp] = num;
          } else {
            ret[exp] = FIELD['add'](ret[exp], num);
          }
        }
        return ret;
    }
    throw "Invalid Param";
  }
function ( x ) { var ret = { } ; if ( x === null || x === undefined ) { x = 0 ; } switch ( typeof x ) { case "object" : if ( x [ 'coeff' ] ) { x = x [ 'coeff' ] ; } if ( Fraction && x instanceof Fraction || Complex && x instanceof Complex || Quaternion && x instanceof Quaternion ) { ret [ 0 ] = x ; } else // Handles Arrays the same way for ( var i in x ) { if ( ! FIELD [ 'empty' ] ( x [ i ] ) ) { ret [ i ] = FIELD [ 'parse' ] ( x [ i ] ) ; } } return ret ; case "number" : return { '0' : FIELD [ 'parse' ] ( x ) } ; case "string" : var tmp ; while ( null !== ( tmp = STR_REGEXP [ 'exec' ] ( x ) ) ) { var num = 1 ; var exp = 1 ; if ( tmp [ 4 ] !== undefined ) { num = tmp [ 4 ] ; exp = 0 ; } else if ( tmp [ 2 ] !== undefined ) { num = tmp [ 2 ] ; } num = parseExp ( tmp [ 1 ] , num ) ; // Parse exponent if ( tmp [ 3 ] !== undefined ) { exp = parseInt ( tmp [ 3 ] , 10 ) ; } if ( ret [ exp ] === undefined ) { ret [ exp ] = num ; } else { ret [ exp ] = FIELD [ 'add' ] ( ret [ exp ] , num ) ; } } return ret ; } throw "Invalid Param" ; }
Parses the actual number

@param {String|Object|null|number} x The polynomial to be parsed
@returns {Object}
Parses the actual number