M

map

map Array prototype function

Blah.

function expand_shorthand(hand) {
    return hand.map(function (value) {
        return {
            rank: value.slice(0, -1),
            suit: value.slice(-1)
        };
    });
});

var hand = expand_shorthand(['AH', 'KH', 'QH', 'JH', '10H']);
// hand is [
//     {suit: 'H', rank: 'A'},
//     {suit: 'H', rank: 'K'},
//     {suit: 'H', rank: 'Q'},
//     {suit: 'H', rank: 'J'},
//     {suit: 'H', rank: '10'}
// ]

match

match String prototype function

Blah.

Math

Math function

The standard does not require implementations to compute the most accurate result from these functions. Implementors are allowed to tradeoff accuracy for speed or other considerations. Blah.

Most of the functions can take one parameter. These are the results of those functions for some particular arguments:

Math
function
Value of a single argument
NaN -0 0 -Infinity Infinity
abs NaN 0 0 Infinity Infinity
acos NaN Math.PI / 2 Math.PI / 2 NaN NaN
asin NaN -0 0 NaN NaN
atan NaN -0 0 -Math.PI / 2 Math.PI / 2
ceil NaN -0 0 -Infinity Infinity
cos NaN 1 1 NaN NaN
exp NaN 1 1 0 Infinity
floor NaN -0 0 -Infinity Infinity
log NaN -Infinity -Infinity NaN Infinity
max NaN -0 0 -Infinity Infinity
min NaN -0 0 -Infinity Infinity
round NaN -0 0 -Infinity Infinity
sin NaN -0 0 NaN NaN
sqrt NaN -0 0 NaN Infinity
tan NaN -0 0 NaN NaN

Math.max(...) and Math.min(...) can take many arguments. The table shows the case where there is one argument.

Math.atan2(y, x) and Math.pow(x, y) each take two arguments. Math.random() takes no arguments.

Math global object

Blah.

Math number

The Math global object is the container for these numeric properties:

max

max Math function

The Math.max(...) function returns the largest number from its arguments. It can take a variable number of arguments. If there are no arguments, it returns -Infinity. If there is one argument, it returns the numeric value of that argument. Otherwise, it compares each of the arguments and returns the greatest. If any of the arguments is NaN or converts to NaN, then the result is NaN. Unlike the > infix operator, Math.max(...) sees -0 as being less than 0 (see zero).

It could be implemented like this:

Math.max = function () {
    var i, length = arguments.length, result = -Infinity, value;
    for (i = 0; i < length; i += 1) {
        value = +arguments[i];
        if (isNaN(value)) {
            return NaN;
        }
        if (value > result ||
                (value === 0 && result === 0 && 1 / value > 0)) {
            result = value;
        }
    }
    return result;
};
Math.max(25, 52)           // 52
Math.max(-1, 0.1, -0.1)    // 0.1
Math.max('2', '10')        // 10

To find the greatest element in an array, use the apply prototype function.

Math.max.apply(null, [40, 8, Math.PI, 1000, 1])    // 1000

MAX_VALUE

MAX_VALUE Number number

Number.MAX_VALUE contains the largest positive representable number. It is approximately equal to 1.7976931348623157e+308. A result which is larger than MAX_VALUE is represented as Infinity. Surprisingly, Number.MAX_VALUE + x where x is a non-negative number in most cases does not produce Infinity. If x is less than approximately 9.979201547673598e+291 then the result of the addition is MAX_VALUE and not Infinity. As a result, even given infinite time, this loop will never break:

for (var x = Number.MAX_VALUE; x !== Infinity; x += 9.979201547673598e+291) {
    x += 1;
}

member

Also known as property. See object.

memoization

Blah.

function memoizer(memo, formula) {
    var recur = function (n) {
        var result = memo[n];
        if (typeof result !== 'number') {
            result = formula(recur, n);
            memo[n] = result;
        }
        return result;
    };
    return recur;
};

var factorial = memoizer([1, 1], function (recur, n) {
    return n * recur(n - 1);
});

var fibonacci = memoizer([0, 1], function (recur, n) {
    return recur(n - 1) + recur(n - 2);
});

method

A method is property whose value is a function. The function gets access to the object with the this parameter. See invocation.

All values except null and undefined can have methods.

method chaining

See cascading.

min

min Math function

The Math.min(...) function returns the smallest number from its arguments. It can take a variable number of arguments. If there are no arguments, it returns Infinity. If there is one arguments, it returns the numeric value of that argument. Otherwise, it compares each of the arguments and returns the lowest. If any of the arguments is NaN or converts to NaN, then the result is NaN. Unlike the < infix operator, Math.min(...) sees -0 as being less than 0 (see zero). It could be implemented like this:

Math.min = function () {
    var i, length = arguments.length, result = Infinity, value;
    for (i = 0; i < length; i += 1) {
        value = +arguments[i];
        if (isNaN(value)) {
            return NaN;
        }
        if (value < result ||
                (value === 0 && result === 0 && 1 / value < 0)) {
            result = value;
        }
    }
    return result;
};
Math.min(25, 52)           // 25
Math.min(-1, 0.1, -0.1)    // -1
Math.min('2', '10')        // 2

To find the least element in an array, use the append prototype function.

Math.min.apply(null, [40, 8, Math.PI, 1000, 1])    // 1

minification

Blah.

minus sign

See - minus sign.

MIN_VALUE

MIN_VALUE Number number

Number.MIN_VALUE is the smallest positive number that can be represented. It is approximately equal to 5e-324. Dividing this value by 2 produces 0.

modulo

Blah.

See % infix operator remainder.

monad

Blah.

monkey patching

Blah.

multiline

multiline RegExp instance number

Blah.

multiply

See * infix operator multiply.

mutability

Blah.