# Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Eloquent JavaScript Exercises

• This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
• Author
Posts
• #144507
Kuzyo
Participant

After reading some JS books, was very difficult to find simple, but usefull exercise which help you to properly understand main JS concept ( furthermore, for me, because I don’t have any programming experiance ). Here I found greate exercises http://www.openbookproject.net/books/mi2pwjs/exercises/ch01/ch01s01.html, maybe sameone find it usefull too.

P.S. I think that in process of solving I will find some problem that I can’t understand, or somehow solve, or my variant of solving will be looks awfull. I will be asking for help and will be glad to hear any advices. Thanks.

**My first, such problem:**
Write a function mirror that takes a string, s, as an argument and returns the letters in s followed by the letters in s backwards. mirror(“yes”) should return “yessey” and mirror(“JS”) should return “JSSJ”.

Here my solution:

function mirror( s ) {
var origArr = [],
revArr = [];
for ( var i = 0; i < s.length; i++ ) {
origArr.push( s[i] );
revArr.push ( s[i] );
}
origArr.push( revArr.reverse().join(“”) );
return origArr.join(“”);

}

console.log( mirror(“yes”) )
For me it looks too difficult, any advice how I can write it more elegant? Thanks.

#144511
apoorvparijat
Participant

function mirror(str) {
return (str + str.split(“”).reverse().join(“”))
}

#144522
Kuzyo
Participant

That’s great illustration of what I have talked. About more simple solution can’t even dream :) Thanks.

#144662
Kuzyo
Participant

Question #2:

Maybe, the problem with language barrier, but I really can’t understand what I have to do, Can somebody explain more simple or show example. Thanks in advance.

Create an object named **counts** that will hold the “count” (i.e. the number of occurances) of things added to it by **addToCounts** below.

Then write a function named **addToCounts(thing)** which tracks inside counts the number of times thing is sent to it.
The following sequence of **addToCount** calls starting with an empty count

addToCounts(‘a’);
addToCounts(7);
addToCounts(‘b’);
addToCounts(7);
addToCounts(‘b’);
should result in a counts object with the following state (when viewed in Firebug):

Object{a=1, 7=2, b=2}

#144727
Baerspective
Participant

@Kuzyo, what books, videos did u learn with? I am learning also and have no programming background. So many books, videos claim to be for real beginners, but then move too fast not explaining step by step or explaining why this is done or used in a certain way. Very frustrating to me. Am struggling to keep up.
Do you have more JS exercise sites you practice with?

#144742
Kuzyo
Participant
Viewing 6 posts - 1 through 6 (of 6 total)
• The forum ‘JavaScript’ is closed to new topics and replies.