Last active
August 29, 2015 14:05
-
-
Save huang-x-h/617de7d3df1dea3535ea to your computer and use it in GitHub Desktop.
常用一些js处理函数
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isPalindrome(str) { return str.split('').reverse().join('') === str; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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