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.
//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) {}
- }
describe("You shoud create an local database with two methods", _ => { it("You shoud create an local database", _ => { var db = new Local_Database; assertEquals(db.set("name", "database"), true); assertEquals(db.get("name"), "database"); }); it("should also work for my custom test cases", _ => { assertEquals(db.set("web_site", "codewars"), true); assertEquals(db.get("web_site"), "codewars"); }); });
Test.describe("Your <code>DataSet()</code> Class", _ => {Test.it("should work for the example provided in the description", _ => {var myData1 = new DataSet(1,2,3,4,5,6,7);Test.assertSimilar(myData1.data, [1,2,3,4,5,6,7]);Test.assertEquals(myData1.mean, 4);Test.assertEquals(myData1.variance, 4);Test.assertEquals(myData1.stdDeviation, 2);myData1.data[6] = 14;myData1.reset();Test.assertEquals(myData1.mean, 5);Test.assertEquals(myData1.variance, 16);Test.assertEquals(myData1.stdDeviation, 4);- describe("You shoud create an local database with two methods", _ => {
- it("You shoud create an local database", _ => {
- var db = new Local_Database;
- assertEquals(db.set("name", "database"), true);
- assertEquals(db.get("name"), "database");
- });
Test.it("should also work for my custom test cases", _ => {// Add your own test cases here :)- it("should also work for my custom test cases", _ => {
- assertEquals(db.set("web_site", "codewars"), true);
- assertEquals(db.get("web_site"), "codewars");
- });
- });