From fa5d32f72647dd316ef886c90c70926ac522bc30 Mon Sep 17 00:00:00 2001 From: Elder Henrique Souza Date: Tue, 12 Dec 2017 16:11:13 -0200 Subject: [PATCH] get max value from array just a version to get the max value from an array --- snippets/get-max-value-from-array.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 snippets/get-max-value-from-array.md diff --git a/snippets/get-max-value-from-array.md b/snippets/get-max-value-from-array.md new file mode 100644 index 000000000..ca606cc83 --- /dev/null +++ b/snippets/get-max-value-from-array.md @@ -0,0 +1,8 @@ +### Get max value from array + +Passing an array, it executes the Math.max method using the spread operator to fill its variadic arguments and returns the maximum value found in the array. + +```js +const getMaxValue = arr => Math.max(...arr); +// getMaxValue([10, 1, 5]) -> 10 +```