Ad
Databases

In this task, you will have to create a class called Local_Database.

Methods

set -> to set data in the local-database. With two parameters key and its value, it must return true if the value was setted.

get -> to get the item located in the database. With one parameter, it must return the value of the corresponding key.

Proprieties

data -> an array or object with the data.

Code
Diff
  • //Off you go!
    
    class Local_Database {
      constructor() {
        this.data = null;
      }
      
      set(key, value) {}
      
      get(key, value) {}
    }
    • class DataSet {
    • constructor(...data) {
    • this.data = data;
    • }
    • get mean() {
    • return this._mean = (this._mean !== undefined) ? this._mean
    • : this.data.reduce((a, b) => a + b) / this.data.length
    • }
    • get variance() {
    • return this._variance = this._variance !== undefined ? this._variance
    • : this.stdDeviation ** 2;
    • }
    • get stdDeviation() {
    • return this._stdDeviation = (this._stdDeviation !== undefined) ? this._stdDeviation
    • : Math.sqrt(
    • this.data.map(x => x * x).reduce((a, b) => a + b) / this.data.length
    • - (this.data.reduce((a, b) => a + b) / this.data.length) ** 2);
    • }
    • reset() {
    • delete this._mean;
    • delete this._variance;
    • delete this._stdDeviation;
    • //Off you go!
    • class Local_Database {
    • constructor() {
    • this.data = null;
    • }
    • set(key, value) {}
    • get(key, value) {}
    • }