Build these 10 coding challenges to get ready for your next tech interview.
29 |
30 | These challenges are some of the most common whiteboard challenges that our students face. First
31 | try and build them. If you still need some help we have built a FREE course on learn.coderfoundry.com.
33 |
34 |
Sign up for your FREE account today to get this course!
39 | Given an array of numbers [1,3,5,7,9] write a function that accepts
40 | the array of numbers and returns the sum of all the numbers in the
41 | array USING RECURSION.
42 | Display a message showing the result of the function and the values
43 | in the array.
44 |
Given an array of numbers [9, 1, 3, 27, 15, -5, 13, 7] write a function that accepts the
29 | array of numbers and returns the sum of all the numbers in the array. Display a message showing the
30 | result of the function and the values in the array.
31 |
32 |
Extra Credit: Create additional functions the return the average, max and min
33 | values of the array
27 | Write a program that prints the numbers from 1 to 100 and for multiples of ‘3’ print “Fizz” instead of the
28 | number and for the multiples of ‘5’ print “Buzz”. Print “FizzBuzz” for numbers which are multiples of both 3
29 | and 5.
30 |
31 |
32 | Implement your function using a ternary operator.
33 | Your method should return an array of values.
34 | Display the array of values on the page.
35 |
36 |
37 | Extra credit: Allow the user to vary the range of numbers displayed and the fizz and buzz values.
38 |
Given an array of city data. Write a function that takes an array of objects as a
29 | parameter. Sort the objects by population in desc order. Display the newly sorted array.
30 |
31 |
Extra Credit:
32 | Sort the city data by the population ascending order
33 | Sort the city data by the city name
34 | Sort the city data by median age
35 |
Given a string write a function that counts the vowels in the string. The function
29 | should return an integer of the vowel count. Display a message indicating the result of the function.
30 |
31 |
Note: For the purposes of this challenge a vowel is (a e i o u).
32 |
33 |
Examples
34 |
35 |
"Hello" = 2 vowels (e,o)
36 |
monkey = 2 vowels (o,e) we are ignoring y for this challenge
37 |
William Shakespeare = 8 vowels (i,a,e) we are counting duplciates.
38 |
39 |
40 |
Extra Credit: Have your function return the vowel count AND the vowels found.
Given a string write a function that checks if the string is a palindrome. The function
29 | should return a boolean (true or false). Display a message indicating the result of the function.
30 |
31 |
Note: A palindrome is a word, phrase, or other sequence of characters which reads
32 | the same backward as forward, such as madam or racecar. You must account for letters and specials
33 | characters for checking
34 |
35 |
Examples of palindromes
36 |
37 |
radar
38 |
taco cat
39 |
Eva, can I see bees in a cave? ("," and "?" and spaces are NOT considered)
Given an array of marvel heroes, write a function that accepts the array of names (strings).
29 | The function should return the hero with the longest name. The user should click the
30 | button to display the heroes name below.
Given the provided block of text, from Alice in Wonderland (string) write a function that accepts the text
29 | (string). The function should return an array of objects with the top 3 most used words and the
30 | counts. Display the top 3 words and their
31 | counts. Consider only letters and numbers and filter out any special characters.
42 | Extra Credit: Filter out stop words using the stop list provided. Stop words are
43 | words that do not provide any useful information to infer content or nature.
44 |
Given two strings write a function that checks if they are anagrams. The function
29 | should return true or false. Display a message indicating the result of the function.
30 |
31 |
Note: An anagram is a word or phrase formed by rearranging the letters of a
32 | different word or phrase.
33 |
Given the string [()]{}{[()()]()}, write a function
29 | that takes a string parameter containing brackets, determine if all brackets have a matching
30 | counterpart. If all brackets in the string form balanced pairs, return true. If not, return false.
31 |
32 |
What are a balanced brackets?
33 |
34 |
Note: You can use these scenarios to test your function
Given an array of marvel heroes write a function that accepts hero alias (string).
29 | The
30 | function should return correponding hero object. Display the hero object which includes their
31 | secret
32 | identity (name). If the search cannot find a hero return a blank object and display a message
33 |
`;
141 | });
142 | tbody.innerHTML = "";
143 | tbody.innerHTML = trow;
144 | }
145 |
146 | //takes an array of objects and sorts by population.
147 | function sortByPopulation(cityData, sortDir) {
148 |
149 | }
150 |
151 | //takes an array of objects and sorts by median age.
152 | function sortByAge(cityData, sortDir){
153 |
154 | }
155 |
156 | //takes an array of objects and sorts by city name.
157 | function sortyByName(cityData) {
158 |
159 | }
--------------------------------------------------------------------------------
/Challenge10/book.js:
--------------------------------------------------------------------------------
1 | const bookText = `ALICE'S ADVENTURES IN WONDERLAND
2 |
3 | Lewis Carroll
4 |
5 | CHAPTER I. Down the Rabbit-Hole
6 |
7 | Alice was beginning to get very tired of sitting by her sister on the
8 | bank, and of having nothing to do: once or twice she had peeped into the
9 | book her sister was reading, but it had no pictures or conversations in
10 | it, 'and what is the use of a book,' thought Alice 'without pictures or
11 | conversations?'
12 |
13 | So she was considering in her own mind (as well as she could, for the
14 | hot day made her feel very sleepy and stupid), whether the pleasure
15 | of making a daisy-chain would be worth the trouble of getting up and
16 | picking the daisies, when suddenly a White Rabbit with pink eyes ran
17 | close by her.
18 |
19 | There was nothing so VERY remarkable in that; nor did Alice think it so
20 | VERY much out of the way to hear the Rabbit say to itself, 'Oh dear!
21 | Oh dear! I shall be late!' (when she thought it over afterwards, it
22 | occurred to her that she ought to have wondered at this, but at the time
23 | it all seemed quite natural); but when the Rabbit actually TOOK A WATCH
24 | OUT OF ITS WAISTCOAT-POCKET, and looked at it, and then hurried on,
25 | Alice started to her feet, for it flashed across her mind that she had
26 | never before seen a rabbit with either a waistcoat-pocket, or a watch
27 | to take out of it, and burning with curiosity, she ran across the field
28 | after it, and fortunately was just in time to see it pop down a large
29 | rabbit-hole under the hedge.
30 |
31 | In another moment down went Alice after it, never once considering how
32 | in the world she was to get out again.
33 |
34 | The rabbit-hole went straight on like a tunnel for some way, and then
35 | dipped suddenly down, so suddenly that Alice had not a moment to think
36 | about stopping herself before she found herself falling down a very deep
37 | well.
38 |
39 | Either the well was very deep, or she fell very slowly, for she had
40 | plenty of time as she went down to look about her and to wonder what was
41 | going to happen next. First, she tried to look down and make out what
42 | she was coming to, but it was too dark to see anything; then she
43 | looked at the sides of the well, and noticed that they were filled with
44 | cupboards and book-shelves; here and there she saw maps and pictures
45 | hung upon pegs. She took down a jar from one of the shelves as
46 | she passed; it was labelled 'ORANGE MARMALADE', but to her great
47 | disappointment it was empty: she did not like to drop the jar for fear
48 | of killing somebody, so managed to put it into one of the cupboards as
49 | she fell past it.
50 |
51 | 'Well!' thought Alice to herself, 'after such a fall as this, I shall
52 | think nothing of tumbling down stairs! How brave they'll all think me at
53 | home! Why, I wouldn't say anything about it, even if I fell off the top
54 | of the house!' (Which was very likely true.)
55 |
56 | Down, down, down. Would the fall NEVER come to an end! 'I wonder how
57 | many miles I've fallen by this time?' she said aloud. 'I must be getting
58 | somewhere near the centre of the earth. Let me see: that would be four
59 | thousand miles down, I think--' (for, you see, Alice had learnt several
60 | things of this sort in her lessons in the schoolroom, and though this
61 | was not a VERY good opportunity for showing off her knowledge, as there
62 | was no one to listen to her, still it was good practice to say it over)
63 | '--yes, that's about the right distance--but then I wonder what Latitude
64 | or Longitude I've got to?' (Alice had no idea what Latitude was, or
65 | Longitude either, but thought they were nice grand words to say.)
66 |
67 | Presently she began again. 'I wonder if I shall fall right THROUGH the
68 | earth! How funny it'll seem to come out among the people that walk with
69 | their heads downward! The Antipathies, I think--' (she was rather glad
70 | there WAS no one listening, this time, as it didn't sound at all the
71 | right word) '--but I shall have to ask them what the name of the country
72 | is, you know. Please, Ma'am, is this New Zealand or Australia?' (and
73 | she tried to curtsey as she spoke--fancy CURTSEYING as you're falling
74 | through the air! Do you think you could manage it?) 'And what an
75 | ignorant little girl she'll think me for asking! No, it'll never do to
76 | ask: perhaps I shall see it written up somewhere.'
77 |
78 | Down, down, down. There was nothing else to do, so Alice soon began
79 | talking again. 'Dinah'll miss me very much to-night, I should think!'
80 | (Dinah was the cat.) 'I hope they'll remember her saucer of milk at
81 | tea-time. Dinah my dear! I wish you were down here with me! There are no
82 | mice in the air, I'm afraid, but you might catch a bat, and that's very
83 | like a mouse, you know. But do cats eat bats, I wonder?' And here Alice
84 | began to get rather sleepy, and went on saying to herself, in a dreamy
85 | sort of way, 'Do cats eat bats? Do cats eat bats?' and sometimes, 'Do
86 | bats eat cats?' for, you see, as she couldn't answer either question,
87 | it didn't much matter which way she put it. She felt that she was dozing
88 | off, and had just begun to dream that she was walking hand in hand with
89 | Dinah, and saying to her very earnestly, 'Now, Dinah, tell me the truth:
90 | did you ever eat a bat?' when suddenly, thump! thump! down she came upon
91 | a heap of sticks and dry leaves, and the fall was over.
92 |
93 | Alice was not a bit hurt, and she jumped up on to her feet in a moment:
94 | she looked up, but it was all dark overhead; before her was another
95 | long passage, and the White Rabbit was still in sight, hurrying down it.
96 | There was not a moment to be lost: away went Alice like the wind, and
97 | was just in time to hear it say, as it turned a corner, 'Oh my ears
98 | and whiskers, how late it's getting!' She was close behind it when she
99 | turned the corner, but the Rabbit was no longer to be seen: she found
100 | herself in a long, low hall, which was lit up by a row of lamps hanging
101 | from the roof.
102 |
103 | There were doors all round the hall, but they were all locked; and when
104 | Alice had been all the way down one side and up the other, trying every
105 | door, she walked sadly down the middle, wondering how she was ever to
106 | get out again.
107 |
108 | Suddenly she came upon a little three-legged table, all made of solid
109 | glass; there was nothing on it except a tiny golden key, and Alice's
110 | first thought was that it might belong to one of the doors of the hall;
111 | but, alas! either the locks were too large, or the key was too small,
112 | but at any rate it would not open any of them. However, on the second
113 | time round, she came upon a low curtain she had not noticed before, and
114 | behind it was a little door about fifteen inches high: she tried the
115 | little golden key in the lock, and to her great delight it fitted!
116 |
117 | Alice opened the door and found that it led into a small passage, not
118 | much larger than a rat-hole: she knelt down and looked along the passage
119 | into the loveliest garden you ever saw. How she longed to get out of
120 | that dark hall, and wander about among those beds of bright flowers and
121 | those cool fountains, but she could not even get her head through the
122 | doorway; 'and even if my head would go through,' thought poor Alice, 'it
123 | would be of very little use without my shoulders. Oh, how I wish I could
124 | shut up like a telescope! I think I could, if I only knew how to begin.'
125 | For, you see, so many out-of-the-way things had happened lately,
126 | that Alice had begun to think that very few things indeed were really
127 | impossible.
128 |
129 | There seemed to be no use in waiting by the little door, so she went
130 | back to the table, half hoping she might find another key on it, or at
131 | any rate a book of rules for shutting people up like telescopes: this
132 | time she found a little bottle on it, ('which certainly was not here
133 | before,' said Alice,) and round the neck of the bottle was a paper
134 | label, with the words 'DRINK ME' beautifully printed on it in large
135 | letters.
136 |
137 | It was all very well to say 'Drink me,' but the wise little Alice was
138 | not going to do THAT in a hurry. 'No, I'll look first,' she said, 'and
139 | see whether it's marked "poison" or not'; for she had read several nice
140 | little histories about children who had got burnt, and eaten up by wild
141 | beasts and other unpleasant things, all because they WOULD not remember
142 | the simple rules their friends had taught them: such as, that a red-hot
143 | poker will burn you if you hold it too long; and that if you cut your
144 | finger VERY deeply with a knife, it usually bleeds; and she had never
145 | forgotten that, if you drink much from a bottle marked 'poison,' it is
146 | almost certain to disagree with you, sooner or later.
147 |
148 | However, this bottle was NOT marked 'poison,' so Alice ventured to taste
149 | it, and finding it very nice, (it had, in fact, a sort of mixed flavour
150 | of cherry-tart, custard, pine-apple, roast turkey, toffee, and hot
151 | buttered toast,) she very soon finished it off.
152 |
153 | 'What a curious feeling!' said Alice; 'I must be shutting up like a
154 | telescope.'
155 |
156 | And so it was indeed: she was now only ten inches high, and her face
157 | brightened up at the thought that she was now the right size for going
158 | through the little door into that lovely garden. First, however, she
159 | waited for a few minutes to see if she was going to shrink any further:
160 | she felt a little nervous about this; 'for it might end, you know,' said
161 | Alice to herself, 'in my going out altogether, like a candle. I wonder
162 | what I should be like then?' And she tried to fancy what the flame of a
163 | candle is like after the candle is blown out, for she could not remember
164 | ever having seen such a thing.
165 |
166 | After a while, finding that nothing more happened, she decided on going
167 | into the garden at once; but, alas for poor Alice! when she got to the
168 | door, she found she had forgotten the little golden key, and when she
169 | went back to the table for it, she found she could not possibly reach
170 | it: she could see it quite plainly through the glass, and she tried her
171 | best to climb up one of the legs of the table, but it was too slippery;
172 | and when she had tired herself out with trying, the poor little thing
173 | sat down and cried.
174 |
175 | 'Come, there's no use in crying like that!' said Alice to herself,
176 | rather sharply; 'I advise you to leave off this minute!' She generally
177 | gave herself very good advice, (though she very seldom followed it),
178 | and sometimes she scolded herself so severely as to bring tears into
179 | her eyes; and once she remembered trying to box her own ears for having
180 | cheated herself in a game of croquet she was playing against herself,
181 | for this curious child was very fond of pretending to be two people.
182 | 'But it's no use now,' thought poor Alice, 'to pretend to be two people!
183 | Why, there's hardly enough of me left to make ONE respectable person!'
184 |
185 | Soon her eye fell on a little glass box that was lying under the table:
186 | she opened it, and found in it a very small cake, on which the words
187 | 'EAT ME' were beautifully marked in currants. 'Well, I'll eat it,' said
188 | Alice, 'and if it makes me grow larger, I can reach the key; and if it
189 | makes me grow smaller, I can creep under the door; so either way I'll
190 | get into the garden, and I don't care which happens!'
191 |
192 | She ate a little bit, and said anxiously to herself, 'Which way? Which
193 | way?', holding her hand on the top of her head to feel which way it was
194 | growing, and she was quite surprised to find that she remained the same
195 | size: to be sure, this generally happens when one eats cake, but Alice
196 | had got so much into the way of expecting nothing but out-of-the-way
197 | things to happen, that it seemed quite dull and stupid for life to go on
198 | in the common way.
199 |
200 | So she set to work, and very soon finished off the cake.`;
201 |
202 |
203 | const testwords = `Hello GoodBye Hello Hello Seeya GoodBye Hello GoodBye Seeya`;
204 |
205 |
--------------------------------------------------------------------------------