Ad
Code
Diff
  • class Human {
        #name;
        #surname;
        #birthday;  
      
        constructor ( name = 'Jhon', surname = 'Doe' , birthday = new Date().toISOString().split`T`[0]) {
            this.#name = name
            this.#surname = surname
            this.#birthday = birthday
        }
      
        get name () {
            return this.#name
        }
      
        get surname () {
            return this.#surname
        }
        
        set name ( newName = 'Jhon' ) {
            this.#name = newName
        }
        
        set surname ( newSurname = 'Doe' ) {
            this.#surname = newSurname
        }
      
        get birthday () {
           return this.#birthday
        }
      
        getAge () {
            return `I'm ${(new Date() - new Date(this.#birthday))/1000/60/60/24/365|0} years old`
        }
      
        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' ) {
    • #birthday;
    • constructor ( name = 'Jhon', surname = 'Doe' , birthday = new Date().toISOString().split`T`[0]) {
    • this.#name = name
    • this.#surname = surname
    • this.#birthday = birthday
    • }
    • get name () {
    • return this.#name
    • }
    • get surname () {
    • return this.#surname
    • }
    • set name ( newName = 'Jhon' ) {
    • this.#name = newName
    • }
    • set surname ( newSurname = 'Doe' ) {
    • this.#surname = newSurname
    • }
    • get birthday () {
    • return this.#birthday
    • }
    • getAge () {
    • return `I'm ${(new Date() - new Date(this.#birthday))/1000/60/60/24/365|0} years old`
    • }
    • 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
    • }
    • }
Code
Diff
  • 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
      
        constructor( name, surname, profession = 'Developer' ){
            super()
            super.name = name
            super.surname = surname
            this.profession = 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
        }
    }
    • 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 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
    • constructor( name, surname, profession = 'Developer' ){
    • super()
    • super.name = name
    • super.surname = surname
    • this.profession = 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
    • }
    • }
Code
Diff
  • // why not ?
    power = ( a, b ) => eval([...Array(b)].fill(a).join`*`)??1
    • // 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 = ( a, b ) => eval([...Array(b)].fill(a).join`*`)??1
Code
Diff
  • class User {
      constructor (name, surname) {
        this.name = name
        this.surname = surname
      }
      
      greeting () {
        return `Hello, my name is ${this.name} ${this.surname}`
      }
      
    }
    
    • function User(name, surname)
    • {
    • class User {
    • constructor (name, surname) {
    • this.name = name
    • this.surname = surname
    • }
    • greeting () {
    • return `Hello, my name is ${this.name} ${this.surname}`
    • }
    • }