# For the programmers who solved the Intermidate scripting programming

For the programmers who solved the Intermidate scripting programming
0

#1

I completed half of the intermidate algorithm programming.
unfortunately, I do it in a very bad way.
I don’t “cheat” - I dont solve it according to the test input, but my solving methods
are pretty straightforward and dull.
I know because I see other people solving these exercises with a neat, elegant and simple way - for example,
look at his clever solutions - https://github.com/Rafase282
Am I doing it right? I feel like an idiot when I finally solve and get a green screen, but after seeing another user’s method which is smarter and simple I feel that I failed and just solved the mission and didn’t improve my algorithm skills.

#2

That’s because usually, those people are more experienced and that’s why they know of all the fancy ways of solving the problems. But to you as a beginner, it’s more important to just be able to figure out how. If anything, even 50 nested IF statements with a bunch of for loops can teach you how to think when working on big code, it’s beneficial too.

You can come back after a few months and solve the challenges better.

#4

At the beginning of my FCC journey I had a similar question and @stewartmurrie gave very good answer.

#5

Solving them is always the first step - if yo ufeel there are better ways to solve a problem then try it out - it’s a standard practice called refactoring and vital in a test driven environment - Red Green Refactor

#6

There will always be someone with a much awesome-er solution, just do what I do. Solve it yourself first than google around for other solutions to see how you can improve yours and you know … try to actually understand what is going on.

I did this for almost every challenge.

#7

Thank you all for the encouraging messages, Today I finally finished Fibonacci Algorithm mission and on the go learned a useful technique - Recursion. Thanks again!

#8

I actually just solved this - and in an attempt to streamline (and based on smart posts from smart people earlier in the day) - I tried to use the reduce function on my fibnoacci array - and I couldn’t get it to work (I don’t want to post my entire answer because it seems it’ll get locked out.

Though I know this won’t give me the right answer - why did this statement return null?

return array.reduce(function(a, b) {
if (b%2 !== 0) {
return a+b;
}
});

I realize i’m not doing the second test - but even still - this return ‘null’ as opposed to a number adding up all the odds in my sequence and I’m not sure why - does anyone know why? Can you use an if in a reduce? Do you need to HAVE an else?

And a quick test shows me yes - you need to have an else - because you must return a (the previous result) when you get an even number or you end up with nothing - which makes sense to me now as I was typing the answer out. If someone feels this should be deleted - have at it - but typing it out is how I solved my problem.

#9

array.reduce takes two arguments. The callback function and an initial value

Also, in the callback the argument you called a is the

previousValue
The value previously returned in the last invocation of the callback, or initialValue, if supplied. (See below.)

If the current value doesnt affect the computation of your reduce you should return this previousValue untouched so the next function can work with it.