2012-04-14 09:05:15Morris

[JavaScript] Return

var identity = function (x) {
  return x;
};

identity(50);


var identity = function (x) {
    return square(x);
};
var square = function (x) {
    return x*x;
}

var identity = function (x) {
  return x;
};

var isOdd = function (n) {
    if (n % 2 === 0) {
        return false;
    } else {
        return true;
    }
};
var isEven = function (n) {
    if(n % 2 === 1) {
        return false;
    } else {
        return true;
    }
}
console.log(isEven(1));
console.log(isEven(2));
console.log(isEven(999));

var lost = [4, 8, 15, 16, 23, 42];
var count = lost.length;

var isLost = function (n) {
    for (var i = 0; i < lost.length; i++) {
        if ( n === lost[i]) {
            return true;
        }
    }
  return false;
};

if ( isLost(12) ) {
  console.log('12 is a lost number');
}

if ( isLost(16) ) {
  console.log('16 is a lost number');
}