J
J
japan1232018-03-14 10:11:11
React
japan123, 2018-03-14 10:11:11

How to find the min and max element of the array immediately after receiving the data?

https://codesandbox.io/s/zn73y6yylm

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-03-14
@japan123

const min = res.data.reduce(
  (acc, el) => (acc > el.price ? el.price : acc),
  Infinity
);

const max = res.data.reduce(
  (acc, el) => (acc < el.price ? el.price : acc),
  -Infinity
);

this.setState({ studios: res.data, isLoading: false, min, max });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question