function Car teg none this teg teg Car prototype getSpeed function arr

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function Car(teg = 'none') {
this.teg = teg;
}
Car.prototype.getSpeed = function (array = []) {
if (array === undefined)
return;
let tempArr = [];
for (let i = 0; i < array.length; i++)
tempArr.push(array[i].speed);
return tempArr;
}
Car.prototype.getMaxSpeed = function (arr = [], array = []) {
if (array === undefined || arr === undefined)
return;
let tempArr = [];
for (let i = 0; i < array.length; i++)
if (arr[i] === Math.max(...arr))
tempArr.push(array[i]);
return tempArr;
}
const arrayCar = [ {name: 'BMW', speed: 20, color: 'red'},
{name: 'Shkoda', speed: 110, color: 'green'},
{name: 'Dodge', speed: 110, color: 'blue'},
{name: 'Maz', speed: 60, color: 'black'}];
Car.prototype.getMaxSpeed(Car.prototype.getSpeed(arrayCar), arrayCar).forEach(element => {
console.log(element)
});