how to tell the customer which route and cheapest price.
For example: how to know which destination is cheaper between Guarulhos to Rio or SaoPaulo to Rio
The form I present in the code I am just adding everything, I would like to display the cheapest of the Keys: Price and Distance
import React, { Component } from "react";
import ReactDOM from "react-dom";
class App extends Component {
state = {
routes: [
{ grarulhoserio: 1, Price: 10, Distance: 345, Sigla: 'grarulhos.rio' },
{ grarulhosesantacatarina: 2, Price: 18, Distance: 547, "Sigla": 'grarulhos.santacatarina' },
{ saopauloerio: 3, Price: 10, Distance: 357, Sigla: 'saopaulo.rio' },
{ minasgeraiserio: 4, Price: 75, Distance: 556, Sigla: 'minasgerais.rio' },
{ minasgeraisesantacatarina: 5, Price: 20, Distance: 1180, Sigla: 'minasgerais.santacatarina' },
{ saopauloesantacatarina: 6, Price: 5, Distance: 512, Sigla: 'saopaulo.santacatarina' }
]
};
onChange = (index, val) => {
this.setState({
routes: this.state.routes.map((route, i) =>
i === index ? { ...route, count: val } : route
)
});
};
render() {
return (
<div>
<ProductList routes={this.state.routes} onChange={this.onChange} />
<Total routes={this.state.routes} />
</div>
);
}
}
const ProductList = ({ routes, onChange }) => (
<ul>
{routes.map((route, i) => (
<li key={i}>
{route.Sigla}
<input
type="text"
value={route.Price}
onChange={e => onChange(i, parseInt(e.target.value) || 0)}
/>
</li>
))}
</ul>
);
const Total = ({ routes }) => (
<h3>
Best Values:
{routes.reduce((sum, i) => (sum += i.Distance * i.Price), 0)}
</h3>
);
ReactDOM.render(<App />, document.querySelector("#root"));