Home › Forums › JavaScript › Eloquent JavaScript Exercises
- This topic is empty.
-
AuthorPosts
-
July 25, 2013 at 3:59 am #144507
Kuzyo
ParticipantAfter 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.July 25, 2013 at 4:39 am #144511apoorvparijat
Participantfunction mirror(str) {
return (str + str.split(“”).reverse().join(“”))
}July 25, 2013 at 5:29 am #144522Kuzyo
ParticipantThat’s great illustration of what I have talked. About more simple solution can’t even dream :) Thanks.
July 26, 2013 at 2:33 am #144662Kuzyo
ParticipantQuestion #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 countaddToCounts(‘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}
July 26, 2013 at 9:52 am #144727Baerspective
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?July 26, 2013 at 12:50 pm #144742Kuzyo
ParticipantI can recommend two books that really hepls me( will be reading for several times ): http://www.goodreads.com/book/show/4355468-object-oriented-javascript
http://shop.oreilly.com/product/9780596805531.do
this one for references: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference?redirectlocale=en-US&redirectslug=JavaScript%2FReference
Video: https://tutsplus.com/course/javascript-fundamentals/
https://tutsplus.com/course/advanced-javascript-fundamentals/Hope it will help ;)
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.