X
X
Xen_OS2015-09-28 18:41:16
ruby
Xen_OS, 2015-09-28 18:41:16

How to convert the string value of one array to a character and transfer it to another array?

Hello. I'm taking a course at codeacademy. I study Hashes and symbols. Can you please tell me why my code says "Oops, try again. It looks like you didn't add each symbolized string to the symbols array."?

strings = ["HTML", "CSS", "JavaScript", "Python", "Ruby"]

# Add your code below!

symbols = []
strings.each {|s|
    s.to_sym
    symbols.push(s)
}

Why you need to write like this:
symbols.push(s.to_sym)
What's the difference?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Nikiforov, 2015-09-28
@eoffsock

Because it is to_symnot destructive, it returns a character, but does not change the initial value of the variable.

_
_ _, 2015-09-28
@AMar4enko

symbols = strings.map(&:to_sym)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question