Created
April 12, 2013 00:25
-
-
Save JoshOldenburg/5368293 to your computer and use it in GitHub Desktop.
phpjs array_merge, formatted w/ tabs
This file contains 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 array_merge() { | |
// https://github.com/kvz/phpjs/blob/master/functions/array/array_merge.js | |
var args = Array.prototype.slice.call(arguments); | |
var argl = args.length; | |
var arg; | |
var retObj = {}; | |
var k = ''; | |
var argil = 0; | |
var j = 0; | |
var i = 0; | |
var ct = 0; | |
var toStr = Object.prototype.toString; | |
var retArr = true; | |
for (i = 0; i < argl; i++) { | |
if (toStr.call(args[i]) !== '[object Array]') { | |
retArr = false; | |
break; | |
} | |
} | |
if (retArr) { | |
retArr = []; | |
for (i = 0; i < argl; i++) { | |
retArr = retArr.concat(args[i]); | |
} | |
return retArr; | |
} | |
for (i = 0, ct = 0; i < argl; i++) { | |
arg = args[i]; | |
if (toStr.call(arg) === '[object Array]') { | |
for (j = 0, argil = arg.length; j < argil; j++) { | |
retObj[ct++] = arg[j]; | |
} | |
} | |
else { | |
for (k in arg) { | |
if (arg.hasOwnProperty(k)) { | |
if (parseInt(k, 10) + '' === k) { | |
retObj[ct++] = arg[k]; | |
} | |
else { | |
retObj[k] = arg[k]; | |
} | |
} | |
} | |
} | |
} | |
return retObj; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment