# Last element skip in array mapping

**URL:** <https://www.ruby-forum.com/t/last-element-skip-in-array-mapping/170197>\
**Category:** Ruby\
**Created:** [June 13, 2009, 6:00pm UTC](https://www.ruby-forum.com/t/last-element-skip-in-array-mapping/170197 "2009-06-13T18:00:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tarazed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ed8c4c/32.png) [@tarazed](https://www.ruby-forum.com/u/tarazed)\
**Post date:** [June 13, 2009, 6:00pm UTC](https://www.ruby-forum.com/t/last-element-skip-in-array-mapping/170197/1 "2009-06-13T18:00:44Z")

</div>

Still a newbie after 2 years, investigating obscure corners of the  
language (version 1.8). I made some tests based on a discussion in  
\_why’s “bits” RedHanded blog:

a = [1, 2, 3, 4, 5, nil]  
b = [1, 2, 3, 4, 5]  
x = a.map { |k| k.to\_s }.join( “0\n” )  
puts x

s = a.map { |k| k }.join( “0\n” )  
puts s

z = a.to\_a.join( “00\n” )  
puts z

beep = b \* “000\n”  
puts beep

Unless the dummy element is added to the array (as in a) the series does  
not complete for any of the mapping methods. Am I missing something  
here?

Len

---

<div class="post-metadata">

**Author:** ![tarazed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ed8c4c/32.png) [@tarazed](https://www.ruby-forum.com/u/tarazed)\
**Post date:** [June 13, 2009, 6:58pm UTC](https://www.ruby-forum.com/t/last-element-skip-in-array-mapping/170197/2 "2009-06-13T18:58:10Z")

</div>

Len L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> puts s
> 
> z = a.to\_a.join( “00\n” )  
> puts z
> 
> beep = b \* “000\n”  
> puts beep
> 
> Unless the dummy element is added to the array (as in a) the series does  
> not complete for any of the mapping methods. Am I missing something here?

Consider:

puts [1].join(“0”)  
puts [1, nil].join(“0”)

m.

---

<div class="post-metadata">

**Author:** ![tarazed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ed8c4c/32.png) [@tarazed](https://www.ruby-forum.com/u/tarazed)\
**Post date:** [June 13, 2009, 7:21pm UTC](https://www.ruby-forum.com/t/last-element-skip-in-array-mapping/170197/3 "2009-06-13T19:21:01Z")

</div>

On Sat, 13 Jun 2009 09:52:17 -0700, Matt N. wrote:

> > s = a.map { |k| k }.join( “0\n” )  
> > something here?
> 
> Consider:
> 
> puts [1].join(“0”)  
> puts [1, nil].join(“0”)
> 
> m.

Thanks. Back to the documentation.  
Misunderstanding - thought join meant adding the argument string to the  
array element. I see that the argument is a separator between elements.  
Duh! Easy to miss these things at my age (70).

Len
