Created
August 13, 2011 13:24
-
-
Save joseanpg/1143847 to your computer and use it in GitHub Desktop.
https://github.com/ialcazar/JavaScript-Examples/blob/master/arrays/concatenator/concatenator.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
| var concatenate = (function(){ | |
| var params; | |
| //Auxiliares "privados" | |
| function hasElements(){return params.length>0;} | |
| function createString(){ | |
| var res = ""; | |
| for(var i=0;i<params.length;i++){ | |
| res += params[i]; | |
| if(isNotLastParam(i)){res+=",";} | |
| } | |
| return res; | |
| } | |
| function isNotLastParam(p1){ | |
| return (p1<params.length-1); | |
| } | |
| //La lambda protagonista | |
| return function(parameters){ | |
| var result = ""; | |
| params = parameters || [ ]; | |
| if(hasElements()){result = createString();} | |
| return result; | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment