Skip to content

Instantly share code, notes, and snippets.

@huang-x-h
Last active August 29, 2015 14:05
Show Gist options
  • Save huang-x-h/617de7d3df1dea3535ea to your computer and use it in GitHub Desktop.
Save huang-x-h/617de7d3df1dea3535ea to your computer and use it in GitHub Desktop.
常用一些js处理函数
function isInteger(x) { return (x^0) === x; }
function isInteger(x) { return Math.round(x) === x; }
function isInteger(x) { return (typeof x === 'number') && (x % 1 === 0); }
function isPalindrome(str) { return str.split('').reverse().join('') === str; }
function sum(x) {
if (arguments.length == 2) {
return arguments[0] + arguments[1];
} else {
return function(y) { return x + y; };
}
}
console.log(sum(2,3)); // Outputs 5
console.log(sum(2)(3)); // Outputs 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment