This Problem of the Week involves determining the identity of a well-known computer science function and renaming the variables so that the definition makes more sense.  The following is the function definition (obfuscated by me):

var unnamed = (function(a) {
  function b(c, d, e, f) {
    c = c[e = parseInt((f = c.length) / 2)] == d
      ? e
      : e > 0 && c[e] > d
        ? +b.call(a, c.slice(0, e), d)
        : e < f - 1 && c[e] < d
          ? e + 1 + b.call(a, c.slice(e + 1), d)
          : a;
    return this !== a && isNaN(c) ? -1 : c;
  };
  return b;
})({});

What I can tell you is that this function takes in a sorted array (in ascending order) as the first parameter while the second parameter can be any element. You must pass in both parameters to get the expected result. What does this function do? What would you rename the following variables unnamed, “a”, “b”, “c”, “d”, and “e” to make it easier to read?

As is normal, the answer for this Problem of the Week will be posted a week from today on Wednesday, August 15, 2012 was posted here.


1 Comment

POW Answer – Unnamed Function #2 | Chris West's Blog · August 16, 2012 at 1:18 PM

[…] answers the Problem of the Week from May 8, 2012. The identity of this well-known computer science function is the binary search. The following is […]

Leave a Reply

Your email address will not be published. Required fields are marked *