Last active
August 29, 2015 14:18
-
-
Save butchi/8e6c606bea100a0cb933 to your computer and use it in GitHub Desktop.
"+"を使わないプログラミング ref: http://qiita.com/butchi_y/items/3c3e9de3258c6a22ecd0
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 plus(x, y) { | |
return x + y; | |
} | |
ans = plus(5, 3); | |
console.log(ans); // => 8 |
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 plus(x, y) { | |
return x - -y; | |
} |
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 strPlus(str1, str2) { | |
return [str1, str2].join(''); | |
} |
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
var re = /ab+c/; | |
console.log(re.test('ac')); // => false | |
console.log(re.test('abc')); // => true |
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
var re = /abb*c/; | |
console.log(re.test('ac')); // => false | |
console.log(re.test('abc')); // => true |
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
var plusChar = decodeURIComponent('%2B'); | |
var re = new RegExp('ab'.concat(plusChar).concat('c')); | |
console.log(re.test('ac')); // => false | |
console.log(re.test('abc')); // => true |
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
var plusChar = String.fromCharCode(43); | |
var re = new RegExp('ab'.concat(plusChar).concat('c')); | |
console.log(re.test('ac')); // => false | |
console.log(re.test('abc')); // => true |
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 plus(x, y) { | |
return -(-x - y); | |
} |
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 plus(x, y) { | |
for(i=[]; i.length < x; i.push(1)){} | |
for(j=[]; j.length < y; j.push(1)){} | |
tmp = i.concat(j); | |
return tmp.length; | |
} |
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 plus(x, y) { | |
return x-~y-1; | |
} |
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 incr(x) { | |
x++; | |
return x; | |
} | |
var x, ans; | |
x = 5; | |
ans = incr(x); | |
console.log(ans); // => 6 |
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 incr(x) { | |
x = -x; | |
x--; | |
x = -x; | |
return 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 incr(n) { | |
var tmp = []; | |
while(tmp.length <= n) { | |
tmp.push(1); | |
} | |
return tmp.length; | |
} |
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 strPlus() { | |
return str1 + str2; | |
} | |
var str1, str2, ans; | |
str1 = 'Thanks, '; | |
str2 = 'world!'; | |
ans = strPlus(str1, str2); | |
console.log(ans); // => "Thanks, world!" |
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 strPlus(str1, str2) { | |
return str1.concat(str2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment