» Posts on JavaScript Teaser

JavaScript Teaser: Fabulous Fibonacci

Written by Yuri Takhteyev

Fill in the missing line of the following code that implements a function returning the next Fibonacci number every time it's called. var nextFibonacciNumber = (function() { var s = [0, 1]; return function () { // Fill in the missing line here. return s.shift(); }; })(); You should only need to add a single statement, consisting of less than 25 characters. Please post the answer on JSFiddle or similar service, and...

Read More »

JavaScript Teaser: A Missing Character

Written by Yuri Takhteyev

The function getCount() defined below is supposed to return the next number every time it's called, starting with 1. (So, the first call would return 1, the next call would return 2, the next would return 3, and so on.) function getCount() { var magic = function() { getCount = function() { return magic.x += !magic(); }; }; return magic.x = 0 + magic(); } Unfortunately, due to a one missing character, it currently...

Read More »

JavaScript Teaser: Awful Functions

Written by Yuri Takhteyev

Here is our JavaScript Teaser for May 14, 2015. Can you solve it? What does this function return and why? function awful() { function terrible(x, y, z) { return x; } terrible[0] = 'this'; terrible[1] = 'is'; terrible[2] = 'pretty'; terrible[3] = 'terrible!'; terrible.length = 4; return [].map.call(terrible, terrible).join(' '); } Please post the answer on JSFiddle or similar service, and then post...

Read More »

JavaScript Teaser: Jan. 16, 2015

Written by Yuri Takhteyev

Here's the second JavaScript Teaser in our series for JavaScript ninjas. Can you figure it out? Please email Yuri if you want feedback on your answer. Do also let us know your thoughts on the question below (but don't post the answers in the comments section this time, so more people can send answers in.) Thanks! Consider the following code: function getTheAnswerAsync() { return Q.when(...

Read More »

JavaScript Teaser: Jan. 9, 2015

Written by Yuri Takhteyev

Do you love JavaScript as much as we do? This week we're starting to release a series of puzzles for those of you who are into JavaScript … If you know the answer, feel free to post in the comments section below. Explain why this JavaScript expression: ['10', '10', '10'].map(parseInt); returns this array: [ 10, NaN, 2 ] Want to read more from our blog? Check...

Read More »