Ruby: got TypeError when calling function. What's happening? -


I'm a Ruby novice and there is a problem with the code given below to work

 < Code> DEF FactorialAl (N) if n == 0 1 and N * Factile (N-1) End and Factorial (Number)  

I am receiving the error message in Fiction Can not be changed in Array (Type Error) in 'Factor' which I am doing wrong in this case, to help me in answering Anybody capable? Thanks in advance

As McPorter says, number apparently an array is.

So what do you need:

  puts (numbers.map {| n | functional (n)})  

And, incidentally, there is nothing to do with the repetition of your error.

McCander confirmed the principle:

  & gt; Numbers [[1,2,3] & gt; Factorial (number) type error: farnam can not be converted into an array  

And just outside of curiosity, here's how you apply the factorial in rubber without rubber , So that you for large numbers.

  def factorial (n) (1..n) .inject (1) {| Ac, x | AC * x} End  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -