Как вывести на страницу объект у которого выше зарплата

Использовать filter(), sort() нельзя

class Developer{
  constructor(name, surname,skills,salary){
    this.name=name;
    this.surname=surname;
    this.skills=skills;
    this.salary=salary;

  }
 }
Developer.prototype.print = function(){
     document.write(`<p>${this.name} ${this.surname}</p>`)
        for (let i = 0; i < this.skills.length; i++) {
            document.write(`
                <ul>
                    <li>${this.skills[i]}</li>
                </ul>
            `);
        }
}
 
class Frontend extends Developer{

}
class Backend extends Developer{
  constructor(name, surname, skills,direction, salary){
    super(name, surname, skills, salary)
      this.direction=direction
  }
}

let people = []
people.push(new Frontend('Vahan', 'Muadyan',['REACT','HTML','CSS','JS'],400000))
people.push(new Frontend('Marat', 'Ghukasyan',['REACT','HTML','CSS','JS'],500000))
people.push(new Frontend('Stas', 'Danyan',['REACT','HTML','CSS','JS'],300000))
people.push(new Frontend('Ashot', 'Muadyan',['REACT','HTML','CSS','JS'],200000))
people.push(new Frontend('Aram', 'Hakobyan',['REACT','HTML','CSS','JS'],150000))

people.push(new Backend('Aram', 'Ghazaryan',['NODE'],['NODE', 'Angular'],160000))
people.push(new Backend('Ano', 'Smith',['ANGULAR'], ['Angular', 'Laravel', 'Node'],1000000))
people.push(new Backend('Ando', 'Smith',['PHP'], ['Angular', 'RUBY', 'Node'],50000))
people.push(new Backend('Edgar', 'Grigoryan',['ANGULAR'], ['Angular', 'Laravel', 'Node'],190000))
people.push(new Backend('Vahan', 'Muadyan',['PYTHON'], ['Angular', 'DJANGO', 'Node'],450000))

let maxsal=people.map(a=>a.salary)
let res = Math.max(...maxsal).print()//???


Ответы (1 шт):

Автор решения: Denis640Kb

Можно перебором массива. Добавил функцию MaxAmount. Пример:

    class Developer{
        constructor(name, surname,skills,salary){
            this.name=name;
            this.surname=surname;
            this.skills=skills;
            this.salary=salary;

        }
    }
    Developer.prototype.print = function(){
        document.write(`<p>${this.name} ${this.surname}</p>`);
        for (let i = 0; i < this.skills.length; i++) {
            document.write(`
                <ul>
                    <li>${this.skills[i]}</li>
                </ul>
            `);
        }
    };

    class Frontend extends Developer{

    }
    class Backend extends Developer{
        constructor(name, surname, skills,direction, salary){
            super(name, surname, skills, salary);
            this.direction=direction
        }
    }

    let people = [];
    people.push(new Frontend('Vahan', 'Muadyan',['REACT','HTML','CSS','JS'],400000));
    people.push(new Frontend('Marat', 'Ghukasyan',['REACT','HTML','CSS','JS'],500000));
    people.push(new Frontend('Stas', 'Danyan',['REACT','HTML','CSS','JS'],300000));
    people.push(new Frontend('Ashot', 'Muadyan',['REACT','HTML','CSS','JS'],200000));
    people.push(new Frontend('Aram', 'Hakobyan',['REACT','HTML','CSS','JS'],150000));

    people.push(new Backend('Aram', 'Ghazaryan',['NODE'],['NODE', 'Angular'],160000));
    people.push(new Backend('Ano', 'Smith',['ANGULAR'], ['Angular', 'Laravel', 'Node'],1000000));
    people.push(new Backend('Ando', 'Smith',['PHP'], ['Angular', 'RUBY', 'Node'],50000));
    people.push(new Backend('Edgar', 'Grigoryan',['ANGULAR'], ['Angular', 'Laravel', 'Node'],190000));
    people.push(new Backend('Vahan', 'Muadyan',['PYTHON'], ['Angular', 'DJANGO', 'Node'],450000));

    //console.log(people['salary']);
    let maxsal=people.map(a=>a.salary);

    function MaxAmount(Arr){
        let maxval = 0;
        for (let i=0;i<Arr.length;i++){
            if (Arr[i]['salary'] > maxval){
                maxval = Arr[i]['salary']
            }
        }
        return maxval;
    }
    console.log(MaxAmount(people));
    let res = Math.max(...maxsal)

Если нужно именно сделать print результата:

    class Developer{
        constructor(name, surname,skills,salary){
            this.name=name;
            this.surname=surname;
            this.skills=skills;
            this.salary=salary;

        }
    }
    Developer.prototype.print = function(){
        document.write(`<p>${this.name} ${this.surname}</p>`);
        for (let i = 0; i < this.skills.length; i++) {
            document.write(`
                <ul>
                    <li>${this.skills[i]}</li>
                </ul>
            `);
        }
    };

    class Frontend extends Developer{

    }
    class Backend extends Developer{
        constructor(name, surname, skills,direction, salary){
            super(name, surname, skills, salary);
            this.direction=direction
        }
    }

    let people = [];
    people.push(new Frontend('Vahan', 'Muadyan',['REACT','HTML','CSS','JS'],400000));
    people.push(new Frontend('Marat', 'Ghukasyan',['REACT','HTML','CSS','JS'],500000));
    people.push(new Frontend('Stas', 'Danyan',['REACT','HTML','CSS','JS'],300000));
    people.push(new Frontend('Ashot', 'Muadyan',['REACT','HTML','CSS','JS'],200000));
    people.push(new Frontend('Aram', 'Hakobyan',['REACT','HTML','CSS','JS'],150000));

    people.push(new Backend('Aram', 'Ghazaryan',['NODE'],['NODE', 'Angular'],160000));
    people.push(new Backend('Ano', 'Smith',['ANGULAR'], ['Angular', 'Laravel', 'Node'],1000000));
    people.push(new Backend('Ando', 'Smith',['PHP'], ['Angular', 'RUBY', 'Node'],50000));
    people.push(new Backend('Edgar', 'Grigoryan',['ANGULAR'], ['Angular', 'Laravel', 'Node'],190000));
    people.push(new Backend('Vahan', 'Muadyan',['PYTHON'], ['Angular', 'DJANGO', 'Node'],450000));

    //console.log(people['salary']);
    let maxsal=people.map(a=>a.salary);

    function MaxAmount(Arr){
        let maxval = 0;
        for (let i=0;i<Arr.length;i++){
            if (Arr[i]['salary'] > maxval){
                maxval = Arr[i]['salary']
            }
        }
        return maxval;
    }
    function printIt(printThis) {
        var win = window.open();
        self.focus();
        win.document.open();
        win.document.write('<'+'html'+'><'+'body'+'>');
        win.document.write(printThis);
        win.document.write('<'+'/body'+'><'+'/html'+'>');
        win.document.close();
        win.print();
    }
    let res = printIt(MaxAmount(people));

→ Ссылка