Ad
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
        #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
    • }
    • }
Code
Diff
  • 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 = name
    • this.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}`
    • }

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
}
Code
Diff
  • factorial=n=>(x=1,[...{*[Symbol.iterator](){for(i=2;i<=n;i++)yield x*=i}}],x)
    • factorial = n => {
    • let res = 1;
    • for(let i = 2; i <= n; ++i){
    • res *= i;
    • }
    • return res;
    • }
    • factorial=n=>(x=1,[...{*[Symbol.iterator](){for(i=2;i<=n;i++)yield x*=i}}],x)
Code
Diff
  • 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
Code
Diff
  • // 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
Code
Diff
  • squared=n=>n/(1/n)
    • squared
    • =(a,i=2,r=1)=>
    • i?squared(a,i-1,r*a):r
    • squared=n=>n/(1/n)
Code
Diff
  • 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 )))
    • */
Code
Diff
  • upperCase = s => s.toUpperCase``
    • function upperCase(s) {
    • //JUST DO IT
    • }
    • upperCase = s => s.toUpperCase``
Code
Diff
  • isEven=$_$=_=>_<+!+[]<<+!+[]?_===+[]:$_$(_-(+!+[]<<+!+[]))
    • isEven=x=>x%2 === 0;
    • isEven=$_$=_=>_<+!+[]<<+!+[]?_===+[]:$_$(_-(+!+[]<<+!+[]))
Code
Diff
  • isDivisible=(n,...a)=>!a.some(e=>n%e!=0)
    • const isDivisible = (n,...args) => args.every(arg => n % arg == 0);
    • isDivisible=(n,...a)=>!a.some(e=>n%e!=0)
Code
Diff
  • countVowelAtWord = s => s.replace(/[^aeoui]/g,'').length
    
    
    • function countVowelAtWord(str) {}
    • countVowelAtWord = s => s.replace(/[^aeoui]/g,'').length
Code
Diff
  • removeEveryThird=s=>[...s].filter((_,i)=>!i||i%3).join``
    • function removeEveryThird(str) {
    • return str
    • .split('')
    • .filter((x, i) => i === 0 || i % 3)
    • .join('')
    • }
    • removeEveryThird=s=>[...s].filter((_,i)=>!i||i%3).join``