class Human { #name; #surname; constructor ( name = 'Jhon', surname = 'Doe' ) { this.#name = name this.#surname = surname } get name () { return this.#name } get surname () { return this.#surname } set name ( newName = 'Jhon' ) { this.#name = newName } set surname ( newSurname = 'Doe' ) { this.#surname = newSurname } greeting () { return `Hello, my name is ${this.#name} ${this.#surname}` } } class Worker extends Human { #totalDays = 0 #hoursPerWeek = 0 #profession; constructor( name, surname, profession = 'Developer' ){ super() super.name = name super.surname = surname this.#profession = profession } get profession () { return this.#profession } get stats () { return { totalDays: this.#totalDays, hoursPerWeek: this.#hoursPerWeek } } doWork (hours = 8) { if (!(this.#totalDays % 7) && this.#totalDays) this.#hoursPerWeek = hours this.#hoursPerWeek += hours this.#totalDays += 1 return this } changeProfession ( newProfession ) { if ( !newProfession ) throw Error('The profession was not transferred!') if ( typeof newProfession !== 'string' ) throw TypeError('Incorrect new profession type!') this.#profession = newProfession this.#hoursPerWeek = 0 this.#totalDays = 0 return this } }
- class Human {
- #name;
- #surname;
- constructor ( name = 'Jhon', surname = 'Doe' ) {
- this.#name = name
- this.#surname = surname
- }
- get name () {
- return this.#name
- }
- get surname () {
- return this.#surname
- }
- set name ( newName = 'Jhon' ) {
- this.#name = newName
- }
- set surname ( newSurname = 'Doe' ) {
- this.#surname = newSurname
- }
- greeting () {
- return `Hello, my name is ${this.#name} ${this.#surname}`
- }
- }
- class Worker extends Human {
- #totalDays = 0
- #hoursPerWeek = 0
- #profession;
- constructor( name, surname, profession = 'Developer' ){
- super()
- super.name = name
- super.surname = surname
this.profession = profession- this.#profession = profession
- }
- get profession () {
- return this.#profession
- }
- get stats () {
- return {
- totalDays: this.#totalDays,
- hoursPerWeek: this.#hoursPerWeek
- }
- }
- doWork (hours = 8) {
- if (!(this.#totalDays % 7) && this.#totalDays)
- this.#hoursPerWeek = hours
- this.#hoursPerWeek += hours
- this.#totalDays += 1
- return this
- }
- changeProfession ( newProfession ) {
- if ( !newProfession ) throw Error('The profession was not transferred!')
- if ( typeof newProfession !== 'string' ) throw TypeError('Incorrect new profession type!')
- this.#profession = newProfession
- this.#hoursPerWeek = 0
- this.#totalDays = 0
- return this
- }
- }
const { config, assert, expect } = require('chai') config.truncateThreshold = 0 const user0 = new Human(), user1 = new Human('Anatoly', 'Wasserman'), user2 = new Human('Vladimir', 'Zelensky') describe('Humans tests:', () => { it('Creation tests', () => { assert.strictEqual( user0.name, 'Jhon' ) assert.strictEqual( user0.surname, 'Doe' ) assert.strictEqual( user1.name, 'Anatoly' ) assert.strictEqual( user1.surname, 'Wasserman' ) assert.strictEqual( user2.name, 'Vladimir' ) assert.strictEqual( user2.surname, 'Zelensky' ) }) it('Methods tests', () => { assert.strictEqual( user0.greeting(), 'Hello, my name is Jhon Doe' ) assert.strictEqual( user1.greeting(), 'Hello, my name is Anatoly Wasserman' ) assert.strictEqual( user2.greeting(), 'Hello, my name is Vladimir Zelensky' ) }) it('Mutation tests', () => { user0.name = 'Nils' assert.strictEqual( user0.name, 'Nils' ) assert.deepEqual( user0, {} ) user1.name = 'Albert' assert.strictEqual( user1.name, 'Albert' ) assert.deepEqual( user1, {} ) user2.name = 'Johann' assert.strictEqual( user2.name, 'Johann' ) assert.deepEqual( user2, {} ) }) }) const worker0 = new Worker('Nils', 'Bor', 'scientist'), worker1 = new Worker('Albert', 'Einstein','scientist'), worker2 = new Worker('Anatoly'), worker3 = new Worker('Vladimir', 'Zelensky', 'comedian') describe('Wokers tests', () => { it('Creation tests', () => { assert.strictEqual( worker0.name, 'Nils' ) assert.strictEqual( worker0.surname, 'Bor' ) assert.strictEqual( worker0.profession, 'scientist') assert.strictEqual( worker1.name, 'Albert' ) assert.strictEqual( worker1.surname, 'Einstein' ) assert.strictEqual( worker1.profession, 'scientist') }) it('Methods tests', () => { worker0.doWork() assert.deepEqual(worker0.stats,{totalDays:1,hoursPerWeek:8}) worker1.doWork().doWork(7).doWork(9).doWork(11).doWork(5) assert.deepEqual(worker1.stats,{totalDays:5,hoursPerWeek:40}) worker2.doWork().doWork().doWork().doWork().doWork().doWork().doWork().doWork().doWork() assert.deepEqual(worker2.stats,{totalDays:9,hoursPerWeek:24}) worker3.changeProfession('president') assert.strictEqual(worker3.profession, 'president') }) it('Error test', () => { let throwed = false, message, error try { worker0.changeProfession() } catch (err) { [error, message] = [err, err.message] } expect( error ).to.be.an.instanceof(Error, 'Throwed error should be instance of "Error" constructor!') assert.strictEqual( message, 'The profession was not transferred!' ) }) it('TypeError test', () => { let throwed = false, message, error try { worker1.changeProfession(1234) } catch (err) { [error, message] = [err, err.message] } expect( error ).to.be.an.instanceof(TypeError, 'Throwed error should be instance of "TypeError" constructor!') assert.strictEqual( message, 'Incorrect new profession type!' ) }) })
const { config, assert } = require('chai')- const { config, assert, expect } = require('chai')
- config.truncateThreshold = 0
- const user0 = new Human(),
- user1 = new Human('Anatoly', 'Wasserman'),
- user2 = new Human('Vladimir', 'Zelensky')
- describe('Humans tests:', () => {
- it('Creation tests', () => {
- assert.strictEqual( user0.name, 'Jhon' )
- assert.strictEqual( user0.surname, 'Doe' )
- assert.strictEqual( user1.name, 'Anatoly' )
- assert.strictEqual( user1.surname, 'Wasserman' )
- assert.strictEqual( user2.name, 'Vladimir' )
- assert.strictEqual( user2.surname, 'Zelensky' )
- })
- it('Methods tests', () => {
- assert.strictEqual( user0.greeting(), 'Hello, my name is Jhon Doe' )
- assert.strictEqual( user1.greeting(), 'Hello, my name is Anatoly Wasserman' )
- assert.strictEqual( user2.greeting(), 'Hello, my name is Vladimir Zelensky' )
- })
- it('Mutation tests', () => {
- user0.name = 'Nils'
- assert.strictEqual( user0.name, 'Nils' )
- assert.deepEqual( user0, {} )
- user1.name = 'Albert'
- assert.strictEqual( user1.name, 'Albert' )
- assert.deepEqual( user1, {} )
- user2.name = 'Johann'
- assert.strictEqual( user2.name, 'Johann' )
- assert.deepEqual( user2, {} )
- })
- })
- const worker0 = new Worker('Nils', 'Bor', 'scientist'),
- worker1 = new Worker('Albert', 'Einstein','scientist'),
worker2 = new Worker('Anatoly')- worker2 = new Worker('Anatoly'),
- worker3 = new Worker('Vladimir', 'Zelensky', 'comedian')
- describe('Wokers tests', () => {
- it('Creation tests', () => {
- assert.strictEqual( worker0.name, 'Nils' )
- assert.strictEqual( worker0.surname, 'Bor' )
- assert.strictEqual( worker0.profession, 'scientist')
- assert.strictEqual( worker1.name, 'Albert' )
- assert.strictEqual( worker1.surname, 'Einstein' )
- assert.strictEqual( worker1.profession, 'scientist')
- })
- it('Methods tests', () => {
- worker0.doWork()
- assert.deepEqual(worker0.stats,{totalDays:1,hoursPerWeek:8})
- worker1.doWork().doWork(7).doWork(9).doWork(11).doWork(5)
- assert.deepEqual(worker1.stats,{totalDays:5,hoursPerWeek:40})
- worker2.doWork().doWork().doWork().doWork().doWork().doWork().doWork().doWork().doWork()
- assert.deepEqual(worker2.stats,{totalDays:9,hoursPerWeek:24})
- worker3.changeProfession('president')
- assert.strictEqual(worker3.profession, 'president')
- })
- it('Error test', () => {
- let throwed = false, message, error
- try {
- worker0.changeProfession()
- } catch (err) {
- [error, message] = [err, err.message]
- }
- expect( error ).to.be.an.instanceof(Error, 'Throwed error should be instance of "Error" constructor!')
- assert.strictEqual( message, 'The profession was not transferred!' )
- })
- it('TypeError test', () => {
- let throwed = false, message, error
- try {
- worker1.changeProfession(1234)
- } catch (err) {
- [error, message] = [err, err.message]
- }
- expect( error ).to.be.an.instanceof(TypeError, 'Throwed error should be instance of "TypeError" constructor!')
- assert.strictEqual( message, 'Incorrect new profession type!' )
- })
- })
class User { #name; #surname; constructor ( name = 'Jhon', surname = 'Doe' ) { this.#name = name this.#surname = surname } get name () { return this.#name } get surname () { return this.#surname } greeting () { return `Hello, my name is ${this.#name} ${this.#surname}` } }
- class User {
constructor (name, surname) {this.name = namethis.surname = surname- #name;
- #surname;
- constructor ( name = 'Jhon', surname = 'Doe' ) {
- this.#name = name
- this.#surname = surname
- }
- get name () {
- return this.#name
- }
- get surname () {
- return this.#surname
- }
- greeting () {
return `Hello, my name is ${this.name} ${this.surname}`- return `Hello, my name is ${this.#name} ${this.#surname}`
- }
const { config, assert } = require('chai') config.truncateThreshold = 0 const user0 = new User(), user1 = new User('Anatoly', 'Wasserman'), user2 = new User('Vladimir', 'Zelensky') describe("Base tests:", () => { it('Creation tests', () => { assert.strictEqual( user0.name, 'Jhon' ) assert.strictEqual( user0.surname, 'Doe' ) assert.strictEqual( user1.name, 'Anatoly' ) assert.strictEqual( user1.surname, 'Wasserman' ) assert.strictEqual( user2.name, 'Vladimir' ) assert.strictEqual( user2.surname, 'Zelensky' ) }) it('Methods tests', () => { assert.strictEqual( user0.greeting(), 'Hello, my name is Jhon Doe' ) assert.strictEqual( user1.greeting(), 'Hello, my name is Anatoly Wasserman' ) assert.strictEqual( user2.greeting(), 'Hello, my name is Vladimir Zelensky' ) }) it('Mutation tests', () => { user0.name = 'Nils' assert.strictEqual( user0.name, 'Jhon' ) assert.deepEqual( user0, {} ) user1.name = 'Albert' assert.strictEqual( user1.name, 'Anatoly' ) assert.deepEqual( user1, {} ) user2.name = 'Johann' assert.strictEqual( user2.name, 'Vladimir' ) assert.deepEqual( user2, {} ) }) })
- const { config, assert } = require('chai')
- config.truncateThreshold = 0
const user1 = new User('Anatoly', 'Wasserman'),- const user0 = new User(),
- user1 = new User('Anatoly', 'Wasserman'),
- user2 = new User('Vladimir', 'Zelensky')
- describe("Base tests:", () => {
- it('Creation tests', () => {
assert.deepEqual( user1, { name: 'Anatoly', surname: 'Wasserman' } )assert.deepEqual( user2, { name: 'Vladimir', surname: 'Zelensky' } )- assert.strictEqual( user0.name, 'Jhon' )
- assert.strictEqual( user0.surname, 'Doe' )
- assert.strictEqual( user1.name, 'Anatoly' )
- assert.strictEqual( user1.surname, 'Wasserman' )
- assert.strictEqual( user2.name, 'Vladimir' )
- assert.strictEqual( user2.surname, 'Zelensky' )
- })
- it('Methods tests', () => {
- assert.strictEqual( user0.greeting(), 'Hello, my name is Jhon Doe' )
- assert.strictEqual( user1.greeting(), 'Hello, my name is Anatoly Wasserman' )
- assert.strictEqual( user2.greeting(), 'Hello, my name is Vladimir Zelensky' )
- })
- it('Mutation tests', () => {
- user0.name = 'Nils'
- assert.strictEqual( user0.name, 'Jhon' )
- assert.deepEqual( user0, {} )
- user1.name = 'Albert'
- assert.strictEqual( user1.name, 'Anatoly' )
- assert.deepEqual( user1, {} )
- user2.name = 'Johann'
- assert.strictEqual( user2.name, 'Vladimir' )
- assert.deepEqual( user2, {} )
- })
- })
You should create any structure(class, or function constructor, or anything else ) whose return instance of user.
function User(name, surname)
{
this.name = name
this.surname = surname
}
const { config, assert } = require("chai")
config.truncateThreshold = 0
describe("Base tests:", function() {
it(":^)", function() {
assert.deepEqual( new User('Anatoly', 'Wasserman'), { name: 'Anatoly', surname: 'Wasserman' } )
assert.deepEqual( new User('React', 'Developer'), { name: 'React', surname: 'Developer' } )
})
})
factorial = n => eval([...Array(n)].map((_,i)=>++i).join`*`)??1
const factorial = num => num === 1 ? 1 : num * factorial(num - 1)- factorial = n => eval([...Array(n)].map((_,i)=>++i).join`*`)??1
const chai = require("chai"); const assert = chai.assert; chai.config.truncateThreshold=0; describe("factorial", function() { it("should test", function() { assert.strictEqual(factorial( 0 ), 1); assert.strictEqual(factorial( 1 ), 1); assert.strictEqual(factorial( 2 ), 2); assert.strictEqual(factorial( 3 ), 6); assert.strictEqual(factorial( 4 ), 24); assert.strictEqual(factorial( 5 ), 120); assert.strictEqual(factorial( 6 ), 720); assert.strictEqual(factorial( 7 ), 5040); assert.strictEqual(factorial( 8 ), 40320); assert.strictEqual(factorial( 9 ), 362880); assert.strictEqual(factorial( 10 ), 3628800); }); });
- const chai = require("chai");
- const assert = chai.assert;
- chai.config.truncateThreshold=0;
- describe("factorial", function() {
- it("should test", function() {
- assert.strictEqual(factorial( 0 ), 1);
- assert.strictEqual(factorial( 1 ), 1);
- assert.strictEqual(factorial( 2 ), 2);
- assert.strictEqual(factorial( 3 ), 6);
- assert.strictEqual(factorial( 4 ), 24);
- assert.strictEqual(factorial( 5 ), 120);
- assert.strictEqual(factorial( 6 ), 720);
- assert.strictEqual(factorial( 7 ), 5040);
- assert.strictEqual(factorial( 8 ), 40320);
- assert.strictEqual(factorial( 9 ), 362880);
- assert.strictEqual(factorial( 10 ), 3628800);
- });
- });
// why not ? add = x = ( a, b ) => b ? x(a ^ b, (a & b) << 1) : a mul = y = ( a, b, c = 0 ) => !b ? c : y(a << 1, b >>> 1, b & 1 ? add(c, a) : c) power = f = ( a, b ) => b ? f( mul(a, 2), --b ) : a>>1
power=(b,e,p=1)=>e?power(b,e-1,b*p):p- // why not ?
- add = x = ( a, b ) => b ? x(a ^ b, (a & b) << 1) : a
- mul = y = ( a, b, c = 0 ) => !b ? c : y(a << 1, b >>> 1, b & 1 ? add(c, a) : c)
- power = f = ( a, b ) => b ? f( mul(a, 2), --b ) : a>>1
returnFromChild=(toReturn,returnWhat)=> toReturn ? returnWhat : 'no return' /* returnFromChild=(toReturn,returnWhat)=> (res=(((a,b)=>a?b:undefined )(toReturn,returnWhat)))!==undefined?res:'no return' // save structure ))) */
const returnFromChild=(toReturn, returnWhat)=>{const child=(toRet, retWhat)=>{if(toRet){return retWhat}}const retThis = child(toReturn,returnWhat);if(retThis!=undefined){return retThis}return 'no return'}- returnFromChild=(toReturn,returnWhat)=> toReturn ? returnWhat : 'no return'
- /*
- returnFromChild=(toReturn,returnWhat)=>
- (res=(((a,b)=>a?b:undefined )(toReturn,returnWhat)))!==undefined?res:'no return'
- // save structure )))
- */
upperCase = s => s.toUpperCase``
function upperCase(s) {//JUST DO IT}- upperCase = s => s.toUpperCase``
const { assert } = require('chai'); describe("Basic test cases", () => { it("Case 1", () => assert.strictEqual( upperCase("qwerty"), 'QWERTY' )); it("Case 2", () => assert.strictEqual( upperCase("argsdfb"), 'ARGSDFB' )); it("Case 3", () => assert.strictEqual( upperCase("aergagdf"), 'AERGAGDF' )); it("Case 4", () => assert.strictEqual( upperCase("yrukuykiu"), 'YRUKUYKIU' )); });
describe("Tests", () => {it("test", () => {Test.assertEquals(upperCase("qwerty"),'QWERTY')});- const { assert } = require('chai');
- describe("Basic test cases", () => {
- it("Case 1", () => assert.strictEqual( upperCase("qwerty"), 'QWERTY' ));
- it("Case 2", () => assert.strictEqual( upperCase("argsdfb"), 'ARGSDFB' ));
- it("Case 3", () => assert.strictEqual( upperCase("aergagdf"), 'AERGAGDF' ));
- it("Case 4", () => assert.strictEqual( upperCase("yrukuykiu"), 'YRUKUYKIU' ));
- });
isEven=$_$=_=>_<+!+[]<<+!+[]?_===+[]:$_$(_-(+!+[]<<+!+[]))
isEven=x=>x%2 === 0;- isEven=$_$=_=>_<+!+[]<<+!+[]?_===+[]:$_$(_-(+!+[]<<+!+[]))
const expect = require("chai").expect; describe("Solution", function() { it("should be true for 4", function() { expect(isEven(4)).to.equal(true) expect(isEven(7)).to.equal(false) }); });
- const expect = require("chai").expect;
- describe("Solution", function() {
- it("should be true for 4", function() {
expect(isEven(4)).to.equal(true);- expect(isEven(4)).to.equal(true)
- expect(isEven(7)).to.equal(false)
- });
- });
countVowelAtWord = s => s.replace(/[^aeoui]/g,'').length
function countVowelAtWord(str) {}- countVowelAtWord = s => s.replace(/[^aeoui]/g,'').length
// Since Node 10, we're using Mocha. // You can use `chai` for assertions. const chai = require("chai"); const assert = chai.assert; // Uncomment the following line to disable truncating failure messages for deep equals, do: // chai.config.truncateThreshold = 0; // Since Node 12, we no longer include assertions from our deprecated custom test framework by default. // Uncomment the following to use the old assertions: // const Test = require("@codewars/test-compat"); describe("Solution", function() { it("should test for something", function() { // Test.assertEquals(1 + 1, 2); // assert.strictEqual(1 + 1, 2); }); });
- // Since Node 10, we're using Mocha.
- // You can use `chai` for assertions.
- const chai = require("chai");
- const assert = chai.assert;
- // Uncomment the following line to disable truncating failure messages for deep equals, do:
- // chai.config.truncateThreshold = 0;
- // Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
- // Uncomment the following to use the old assertions:
- // const Test = require("@codewars/test-compat");
- describe("Solution", function() {
- it("should test for something", function() {
- // Test.assertEquals(1 + 1, 2);
- // assert.strictEqual(1 + 1, 2);
- });
- });