This forum is now read-only. Please use our new forums at

Big O Forum

View Course » View Exercise

1187 points
Submitted by
Ross Studtman
almost 6 years ago

how can you return "[s]"?

return [s] It's like asking for the data, at index "s", of an array that doesn't exist.

So tried a couple of things in Firebug:

var trippyArrayCreation = function(s){
    return [s];

console.log(trippyFunction("yoyo")); // ["yoyo"]

Since that worked might as well try going with:

console.log(["yoyo"]); // ["yoyo"]

And that works, too. It's like creating an anonymous array? At any rate, there should be a better example to demonstrate exponential growth, where the exponent is n.

1 vote


Yes [s] is an anonymous array containing only the string s, but remember that helper() is just a recursive helper function. It returns something else in the recursive case, so see how [s] is used by that. Simply printing [s] would not accomplish the task of creating an array of all binary strings of length n. I generally try to write functions so that they could be possibly usable outside of the example context that I provide them in. Hope this helps!

389 points
Submitted by
Eric Summers
almost 6 years ago