Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
February 11, 2021 06:10 am GMT

Data Structures Introduction

                   -Which Data Structure is The Best?                   -ES2015 Class Syntax Overview                   -Data Structure: The Class Keyword                   -Data Structure: Adding Instance Methods
Enter fullscreen mode Exit fullscreen mode

Which Data Structure is The Best?

Data structures are collections of values, the relationships among them, and the functions or operations that can be applied to the data. Data structures excel at different things. Some are highly specialized, while others are more generally used.

Visualized Data Structures

Array

Alt Text

Singly Linked List

Alt Text

Hash Table

Alt Text

Tree

Alt Text

Binary Search Tree

Alt Text

Undirected Graph

Alt Text

Directed Graph

Alt Text

All data structures store data, however the relationship between the data and the functionality between methods differ.

ES2015 Class Syntax Overview

What is a class?
A class is a blueprint for creating objects with pre-defined properties and methods.

Class example

class Student {    constructor(firstName, lastName, year){        this.firstName = firstName;        this.lastName = lastName;        this.grade = year;    }}let firstStudent = new Student("Colt", "Steele",1);let secondStudent = new Student("Blue", "Steele",2);
Enter fullscreen mode Exit fullscreen mode

The method to create new objects must be called constructor.
The class keyword creates a constant that can not be redefined.

Data Structure: Adding Instance Methods

class Student {    constructor(firstName, lastName, year){        this.firstName = firstName;        this.lastName = lastName;        this.grade = year;        this.tardies = 0;        this.scores = [];    }    fullName(){        return `Your full name is ${this.firstName} ${this.lastName}`;    }    markLate(){        this.tardies += 1;        if(this.tardies >= 3) {            return "YOU ARE EXPELLED!!!!"        }        return `${this.firstName} ${this.lastName} has been late ${this.tardies} times`;    }    addScore(score){        this.scores.push(score);        return this.scores    }    calculateAverage(){        let sum = this.scores.reduce(function(a,b){return a+b;})        return sum/this.scores.length;    }  }let firstStudent = new Student("Colt", "Steele",1);let secondStudent = new Student("Blue", "Steele",2);
Enter fullscreen mode Exit fullscreen mode

Original Link: https://dev.to/code_regina/data-structures-introduction-5073

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To