Last active
October 27, 2015 08:04
-
-
Save butchi/f727c4f4b55f5e244413 to your computer and use it in GitHub Desktop.
JavaScriptのランプ関数いろいろ ref: http://qiita.com/butchi_y/items/36978607f95f8e5ccf91
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 ramp(x) { | |
return (x < 0) ? 0 : x; | |
} |
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 ramp(x) { | |
return Math.max(x, 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 ramp(x) { | |
return ((Math.sign(x) + 1) / 2) * x; | |
} |
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 ramp(x) { | |
return Number(x.toString().replace(/^-.+/, 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 ramp(x) { | |
return Math.max(x, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment