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

Big O Forum

View Course » View Exercise

1187 points
Picture
Submitted by
Ross Studtman
over 5 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

permalink

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
4f8f6ea95a87fe00030031ad_732049700
Submitted by
Eric Summers
about 5 years ago