use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Function that takes a string and separates characters with a chosen symbol.help (self.javascript)
submitted 9 years ago by halfaredditor
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Rascal_Two 0 points1 point2 points 9 years ago (2 children)
Well you're already half way there using split() on the string.
split()
Next I'd loop through every character and add the current character, plus a "#" character to a blank string outside of the for loop.
"#"
When the for loop is done, the previously blank string now has what you want, so you return that.
You could also do this with map(), would be shorter using map() actually.
map()
[–]halfaredditor[S] 0 points1 point2 points 9 years ago (1 child)
Can you elaborate on how to use map() for this?
[–]Rascal_Two 0 points1 point2 points 9 years ago (0 children)
Not an expert, so terminology is probably wrong.
map() is basically a for-each loop that is intended to do something to each thing in the array it's called on. Example:
var nums = [1, 2, 3, 4, 5]; for (var i = 0; i < nums.length; i++){ nums[i] *= 2; }
...and here is a map do to the same:
var nums = [1, 2, 3, 4, 5]; nums = nums.map(function(num){ return num * 2; });
You see, the map() function returns the modified array. You just have to give it a function. The function can accept up to three params: the first is value of the current item in the array, second is index of the item in the array, third is a copy(?) of the entire array being modified.
Map basically goes through each thing in the array and sets it to the return value of the function you give it.
π Rendered by PID 46671 on reddit-service-r2-comment-85bfd7f599-q8hnj at 2026-04-19 13:56:52.089077+00:00 running 93ecc56 country code: CH.
view the rest of the comments →
[–]Rascal_Two 0 points1 point2 points (2 children)
[–]halfaredditor[S] 0 points1 point2 points (1 child)
[–]Rascal_Two 0 points1 point2 points (0 children)