» Posts on JavaScript Teaser

From REST to GraphQL

Written by David Barreto

I've been hearing about GraphQL lately, a library to create an API endpoint for your data. GraphQL has been positioned as a replacement for our traditional REST backends as it tries to solve the same problem. Which is, to make data available for our web or mobile apps, but with a different approach that is supposed to be more flexible. To be honest, I was...

Read More »

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 »