madbernard: a long angled pier (Default)
[personal profile] madbernard
I've been sick this past week, which didn't stop me vs. 6.1 and 6.2, but when I hit 6.3 I couldn't even figure out what he was asking. It's like he's saying, design a protuberance on the center of your face, then use that protuberance to detect a scent. ...Does he mean find your nose, or does he mean build yourself a new nose? That second one seems a bit unnecessary. Or to be less metaphorical, what am I missing? Iterating over arrays and objects seems like a major portion of what we've been doing so far. The emphasis on interface has got to be meaningful, but the gap between that text analysis and understanding the reason behind the question is fairly daunting.

I'm posting now because I at least figured out something, though I'm fairly sure I'm deep in the weeds heading in a direction that would baffle and amaze all who came after me.

I wondered what methods came baked in to objects, like forEach does on arrays. So I googled, and found this StackExchange bit,

which lead me to screw around in JSBin seeing what came included in the Object package,
console.log(Object.getOwnPropertyNames(Object)); and

And then there were all sorts of interesting things to look up:

Moving forward with Object.keys, I tried this out as a start of an attack on 6.3, adding the console.log stuff in the midst of the program when it initially didn't return what I expected. Thanks to my housemate Ben for that general technique! What I was trying to do here is to get it to pull out a value from a Seq object at any given point:

var Seq = function(object) {
this.object = object;
Seq.prototype.valueAtI = function(i) {
var keyArray = [];
for (var j = 0; j < (i || keyArray.length); j++) {
if (j == i)
return keyArray[i];
return "There are fewer things in the sequence than that";

var foo = new Seq; = "baz";
foo.bear = "bearz";
foo.pear = "pearz";


The results were [[]] / There are fewer things in the sequence than that . I'd varied the value of i, even down to 0 ("undefined"), but it was the second set of brackets that tipped me off. Less broken code below:

Seq.prototype.valueAtI = function(i) {
var keyArray = Object.keys(this);
for (var j = 0; j < (i || keyArray.length); j++) {
if (j == i)
return keyArray[i];
return "There are fewer things in the sequence than that";

This actually results in an array of the keys of the object. It doesn't do what I meant it to do, and I think I can see why now that I'm writing, but it's pretty late and I'm taking the tiny win.
Identity URL: 
Account name:
If you don't have an account you can create one now.
HTML doesn't work in the subject.


Notice: This account is set to log the IP addresses of everyone who comments.
Links will be displayed as unclickable URLs to help prevent spam.

May 2016

8910 11121314

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Oct. 18th, 2017 09:56 pm
Powered by Dreamwidth Studios