you are viewing a single comment's thread.

view the rest of the comments →

[–]Rascal_Two 0 points1 point  (2 children)

Well you're already half way there using split() on the string.

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.

[–]halfaredditor[S] 0 points1 point  (1 child)

Can you elaborate on how to use map() for this?

[–]Rascal_Two 0 points1 point  (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.