Created
April 12, 2017 05:29
-
-
Save anonymous/a32deddce6c6da2402a62393dd03628f to your computer and use it in GitHub Desktop.
5.4 My Join created by smillaraaq - https://repl.it/HEVr/3
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 myJoin(arr,sep) { | |
| let str = ""; | |
| if (!sep) { sep = ","; } | |
| for (let i = 0 ; i < arr.length ; i ++) { | |
| if (arr[i] === undefined||arr[i] === null) { | |
| continue; | |
| } | |
| if (!!str.length) { | |
| str = str + sep; | |
| } | |
| str = str + arr[i]; | |
| } | |
| return str; | |
| } | |
| function myJoin(arr,sep) { | |
| let str = ""; | |
| if (!sep) { | |
| sep = ","; | |
| } | |
| for (let i = 0 ; i < arr.length ; i ++) { | |
| if (arr[i] === undefined||arr[i] === null) { | |
| continue; | |
| }else if (!str.length) { | |
| str = str + arr[i]; | |
| } else { | |
| str = str + sep; | |
| str = str + arr[i]; | |
| } | |
| } | |
| return str; | |
| } | |
| console.log(myJoin([null,undefined, 'hello', undefined, 'world', undefined], ' ')); | |
| // => 'hello world' | |
| console.log(myJoin([2, "be", false])); | |
| // => '2,be,false` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment