DATA
STRUCTURES
Data structures are collections of values, the relationships among them, and the functions or operations that can be applied to the data
Different data structures excel at different things. Some are highly specialized, while others (like arrays) are more generally used.
The more time you spend as a developer, the more likely you'll need to use one of these data structures
You've already worked with many of them unknowingly!
And of course...INTERVIEWS
THERE IS NO ONE "BEST"
DATA STRUCTURE
Does JavaScript really have them?
Ehh....not really
A blueprint for creating objects with pre-defined properties and methods
We're going to implement data structures as classes!
class Student {
constructor(firstName, lastName){
this.firstName = firstName;
this.lastName = lastName;
}
}
The method to create new objects must be called constructor
The class keyword creates a constant, so you can not redefine it. Watch out for the syntax as well!
We use the new keyword
class Student {
constructor(firstName, lastName){
this.firstName = firstName;
this.lastName = lastName;
}
}
let firstStudent = new Student("Colt", "Steele");
let secondStudent = new Student("Blue", "Steele");
class Student {
constructor(firstName, lastName){
this.firstName = firstName;
this.lastName = lastName;
}
fullName(){
return `Your full name is ${this.firstName} ${this.lastName}`;
}
}
let firstStudent = new Student("Colt", "Steele");
firstStudent.fullName() // "Colt Steele"
class Student {
constructor(firstName, lastName){
this.firstName = firstName;
this.lastName = lastName;
}
fullName(){
return `Your full name is ${this.firstName} ${this.lastName}`;
}
static enrollStudents(...students){
// maybe send an email here
}
}
let firstStudent = new Student("Colt", "Steele");
let secondStudent = new Student("Blue", "Steele");
Student.enrollStudents([firstStudent, secondStudent])
class DataStructure(){
constructor(){
// what default properties should it have?
}
someInstanceMethod(){
// what should each object created from this class be able to do?
}
}
We will almost never be using static methods
We will be using the constructor and instance methods quite a bit!
Inside all of our instance methods and constructor, the keyword `this` refers to the object created from that class (also known as an instance)