This course has been updated! We now recommend you take the Complete Intro to Computer Science course.
Transcript from the "Exercise 6: Array List" Lesson
[00:00:00]
>> [MUSIC]
[00:00:03]
>> Brian Holt: What we're gonna do now is I'm gonna work the very first part of this with you, so you can kind of get started. But I want you to actually implement this collapsing part of it. That's the part I'm most interested in having you, because I want you to feel the pain of collapsing an array.
[00:00:20]
>> Brian Holt: It is painful. [LAUGH]
>> Speaker 2: That's what we all wanna hear right now.
>> Brian Holt: You know it, hey, you're the one who decided to come to my class, so.
>> Brian Holt: Okay, so I kind of gave here a description of what I want you do. I want you to have a length, I want you to have push, I want you to have pop, and I want you to have get and delete.
[00:00:46] And then probably internally, you're gonna use some sort of collapse to method. But I'll leave it up to you to call it whatever you want. So we're gonna use ES6 classes. Some of you might find those kinda gross, a lot people do. But they lend themselves well to this problem, so we're just gonna go ahead and do that.
[00:01:03] This is ES6, and you're just creating a new class, right? Nothing too,
>> Brian Holt: Interesting there. We're gonna have a constructor. And I gotta remember all the methods that I put on this.
>> Brian Holt: Okay, and I'll do the constructor for you since this will help you what you're supposed to do.
[00:01:32] this.length = 0 and this.data = object. So I'm gonna make you use an object instead of
>> Brian Holt: An array, because if you use an array that's, cheating, right? Because we're implementing arrays. But basically, I want you to make it so array.0, right, or 0 = 'thing', right? I want that to still work.
[00:02:02] Actually not really, it's gonna be array.
>> Brian Holt: What do I do here, I just have you do push, right?
>> Brian Holt: But yeah, you're gonna have to use an object instead of an array. That's what I wanna get at, and then you're gonna have push.
>> Brian Holt: Push(value).
>> Brian Holt: You're gonna have pop, which is gonna pop something off the top.
[00:02:28] get(index).
>> Brian Holt: delete(index).
>> Brian Holt: Something to note here, for those of you unfamiliar with the class syntax, there's no commas. I don't know why they decided not to put commas in classes, but there are no commas in classes.
>> Brian Holt: Okay, I called this _collapseTo.
>> Brian Holt: This is just an interior utility method, that I would suggest that you implement, that basically says, I'm going to delete index four.
[00:03:06] So I'd pass four into here, so I need you to shift everything else back up one, right, does that makes sense? You can do that inside a delete if you want to, I just wouldn't suggest it. And then you can ignore serialized cuz you won't need it.
>> Brian Holt: Okay, so surprise, surprise.
[00:03:28] I did your first unit test for you, which I think just checks if it's actually a thing, so good job. Yep, so it exists. Now I want you to go in and fill in all of these methods.