Jump to content

update Math.min to show spread operator example. var f = Math.min(...myArray);


thundermoth
 Share

Recommended Posts

<script>
function myFunction() {
  var a = Math.min(5, 10);
  var b = Math.min(0, 150, 30, 20, 38);
  var c = Math.min(-5, 10);
  var d = Math.min(-5, -10);
  var e = Math.min(1.5, 2.5);

  var x = a + "<br>" + b + "<br>" + c + "<br>" + d + "<br>" + e;
  document.getElementById("demo").innerHTML = x;
}
</script>

What about adding something like one of the follow examples to show how to use the spread operator on an array with Math.min?

var myArray = [0, 150, 30, 20, 38];

var f = Math.min(...myArray);

or

var f = [a, b, c, d, e];
var g = Math.min(...f);

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...