Skip to content

Instantly share code, notes, and snippets.

@butchi
Last active August 29, 2015 14:18
Show Gist options
  • Save butchi/8e6c606bea100a0cb933 to your computer and use it in GitHub Desktop.
Save butchi/8e6c606bea100a0cb933 to your computer and use it in GitHub Desktop.
"+"を使わないプログラミング ref: http://qiita.com/butchi_y/items/3c3e9de3258c6a22ecd0
function plus(x, y) {
return x + y;
}
ans = plus(5, 3);
console.log(ans); // => 8
function plus(x, y) {
return x - -y;
}
function strPlus(str1, str2) {
return [str1, str2].join('');
}
var re = /ab+c/;
console.log(re.test('ac')); // => false
console.log(re.test('abc')); // => true
var re = /abb*c/;
console.log(re.test('ac')); // => false
console.log(re.test('abc')); // => true
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
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
function plus(x, y) {
return -(-x - y);
}
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;
}
function plus(x, y) {
return x-~y-1;
}
function incr(x) {
x++;
return x;
}
var x, ans;
x = 5;
ans = incr(x);
console.log(ans); // => 6
function incr(x) {
x = -x;
x--;
x = -x;
return x;
}
function incr(n) {
var tmp = [];
while(tmp.length <= n) {
tmp.push(1);
}
return tmp.length;
}
function strPlus() {
return str1 + str2;
}
var str1, str2, ans;
str1 = 'Thanks, ';
str2 = 'world!';
ans = strPlus(str1, str2);
console.log(ans); // => "Thanks, world!"
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