Skip to main content
se añadieron 175 caracteres en el cuerpo; título editado
Origen Enlace
Marcos
  • 35.7k
  • 7
  • 36
  • 70

como ¿Como puedo encontarencontrar el coste minimomínimo es este array de objetos?

EHe probado varias maneras y los reasultadosresultados son NaN O INFINITYNaN o INFINITY o simplemente me devuelve todos los numerosnúmeros y yo solo quiero el precio menor que seria 90. 

No se si estoy usando bien el metodo math.min()método math.min() o si en un array de objetos es mas complicado.

let flights = [

{ id: 00, to: 'Bilbao', from: 'Barcelona', cost: 1600, scale: false },

{ id: 01, to: 'New York', from: 'Barcelona', cost: 700, scale: false },

{ id: 02, to: 'Los Angeles', from: 'Madrid', cost: 1100, scale: true },

{ id: 03, to: 'Paris', from: 'Barcelona', cost: 210, scale: false },

{ id: 04, to: 'Roma', from: 'Barcelona', cost: 150, scale: false },

{ id: 05, to: 'London', from: 'Madrid', cost: 200, scale: false },

{ id: 06, to: 'Madrid', from: 'Barcelona', cost: 90, scale: false },

{ id: 07, to: 'Tokyo', from: 'Madrid', cost: 1500, scale: true },

{ id: 08, to: 'Shangai', from: 'Barcelona', cost: 800, scale: true },

{ id: 09, to: 'Sydney', from: 'Barcelona', cost: 150, scale: true },

{ id: 10, to: 'Tel-Aviv', from: 'Madrid', cost: 150, scale: false }];
let flights = [
    { id: 00, to: 'Bilbao', from: 'Barcelona', cost: 1600, scale: false },
    { id: 01, to: 'New York', from: 'Barcelona', cost: 700, scale: false },
    { id: 02, to: 'Los Angeles', from: 'Madrid', cost: 1100, scale: true },
    { id: 03, to: 'Paris', from: 'Barcelona', cost: 210, scale: false },
    { id: 04, to: 'Roma', from: 'Barcelona', cost: 150, scale: false },
    { id: 05, to: 'London', from: 'Madrid', cost: 200, scale: false },
    { id: 06, to: 'Madrid', from: 'Barcelona', cost: 90, scale: false },
    { id: 07, to: 'Tokyo', from: 'Madrid', cost: 1500, scale: true },
    { id: 08, to: 'Shangai', from: 'Barcelona', cost: 800, scale: true },
    { id: 09, to: 'Sydney', from: 'Barcelona', cost: 150, scale: true },
    { id: 10, to: 'Tel-Aviv', from: 'Madrid', cost: 150, scale: false }
];

function minPrice(){
    document.write('<h1>Vuelo con el precio mas bajo</h1>')
    for (let i = 0; i < flights.length; i++){
      let min = Math.min(flights[i].cost);
      document.write(min);
      console.log(min);
    }
    
}

minPrice();
function minPrice(){
    document.write('<h1>Vuelo con el precio mas bajo</h1>')
    for (let i = 0; i < flights.length; i++){
    let min = Math.min(flights[i].cost);
    document.write(min);
    console.log(min);
    }
    
  };

  minPrice();
````
 

como puedo encontar el coste minimo es este array de objetos?

E probado varias maneras y los reasultados son NaN O INFINITY o simplemente me devuelve todos los numeros y yo solo quiero el precio menor que seria 90. No se si estoy usando bien el metodo math.min() o si en un array de objetos es mas complicado.

let flights = [

{ id: 00, to: 'Bilbao', from: 'Barcelona', cost: 1600, scale: false },

{ id: 01, to: 'New York', from: 'Barcelona', cost: 700, scale: false },

{ id: 02, to: 'Los Angeles', from: 'Madrid', cost: 1100, scale: true },

{ id: 03, to: 'Paris', from: 'Barcelona', cost: 210, scale: false },

{ id: 04, to: 'Roma', from: 'Barcelona', cost: 150, scale: false },

{ id: 05, to: 'London', from: 'Madrid', cost: 200, scale: false },

{ id: 06, to: 'Madrid', from: 'Barcelona', cost: 90, scale: false },

{ id: 07, to: 'Tokyo', from: 'Madrid', cost: 1500, scale: true },

{ id: 08, to: 'Shangai', from: 'Barcelona', cost: 800, scale: true },

{ id: 09, to: 'Sydney', from: 'Barcelona', cost: 150, scale: true },

{ id: 10, to: 'Tel-Aviv', from: 'Madrid', cost: 150, scale: false }];
function minPrice(){
    document.write('<h1>Vuelo con el precio mas bajo</h1>')
    for (let i = 0; i < flights.length; i++){
    let min = Math.min(flights[i].cost);
    document.write(min);
    console.log(min);
    }
    
  };

  minPrice();
````

¿Como puedo encontrar el coste mínimo es este array de objetos?

He probado varias maneras y los resultados son NaN o INFINITY o simplemente me devuelve todos los números y yo solo quiero el precio menor que seria 90. 

No se si estoy usando bien el método math.min() o si en un array de objetos es mas complicado.

let flights = [
    { id: 00, to: 'Bilbao', from: 'Barcelona', cost: 1600, scale: false },
    { id: 01, to: 'New York', from: 'Barcelona', cost: 700, scale: false },
    { id: 02, to: 'Los Angeles', from: 'Madrid', cost: 1100, scale: true },
    { id: 03, to: 'Paris', from: 'Barcelona', cost: 210, scale: false },
    { id: 04, to: 'Roma', from: 'Barcelona', cost: 150, scale: false },
    { id: 05, to: 'London', from: 'Madrid', cost: 200, scale: false },
    { id: 06, to: 'Madrid', from: 'Barcelona', cost: 90, scale: false },
    { id: 07, to: 'Tokyo', from: 'Madrid', cost: 1500, scale: true },
    { id: 08, to: 'Shangai', from: 'Barcelona', cost: 800, scale: true },
    { id: 09, to: 'Sydney', from: 'Barcelona', cost: 150, scale: true },
    { id: 10, to: 'Tel-Aviv', from: 'Madrid', cost: 150, scale: false }
];

function minPrice(){
    document.write('<h1>Vuelo con el precio mas bajo</h1>')
    for (let i = 0; i < flights.length; i++){
      let min = Math.min(flights[i].cost);
      document.write(min);
      console.log(min);
    }
    
}

minPrice();
 

Origen Enlace

como puedo encontar el coste minimo es este array de objetos?

E probado varias maneras y los reasultados son NaN O INFINITY o simplemente me devuelve todos los numeros y yo solo quiero el precio menor que seria 90. No se si estoy usando bien el metodo math.min() o si en un array de objetos es mas complicado.

let flights = [

{ id: 00, to: 'Bilbao', from: 'Barcelona', cost: 1600, scale: false },

{ id: 01, to: 'New York', from: 'Barcelona', cost: 700, scale: false },

{ id: 02, to: 'Los Angeles', from: 'Madrid', cost: 1100, scale: true },

{ id: 03, to: 'Paris', from: 'Barcelona', cost: 210, scale: false },

{ id: 04, to: 'Roma', from: 'Barcelona', cost: 150, scale: false },

{ id: 05, to: 'London', from: 'Madrid', cost: 200, scale: false },

{ id: 06, to: 'Madrid', from: 'Barcelona', cost: 90, scale: false },

{ id: 07, to: 'Tokyo', from: 'Madrid', cost: 1500, scale: true },

{ id: 08, to: 'Shangai', from: 'Barcelona', cost: 800, scale: true },

{ id: 09, to: 'Sydney', from: 'Barcelona', cost: 150, scale: true },

{ id: 10, to: 'Tel-Aviv', from: 'Madrid', cost: 150, scale: false }];
function minPrice(){
    document.write('<h1>Vuelo con el precio mas bajo</h1>')
    for (let i = 0; i < flights.length; i++){
    let min = Math.min(flights[i].cost);
    document.write(min);
    console.log(min);
    }
    
  };

  minPrice();
````