Tricks in using #javascript Apply function
▻https://hackernoon.com/tricks-in-using-javascript-apply-function-148b1dcb9503?source=rss----3a8
Photo by Isis França on UnsplashDid you ever feel cumbersome when you use the built in JavaScript Functions Math.max and Math.min?Image from google.comWe already know that this two built functions accepts a variable argument-list. For instance when using the Math.max to get the highest value it may be written in this wayMath.max(5,2,1,3,4) // Outputs 5. Works pretty well. How about if we’re dealing with array of values we might write our code in this way.const list = [5,2,1,3,4];Math.max(list[0],list[1],list[2],list[3],list[4],list[5]);What’s wrong in this Implementation?I guess you know what’s wrong in this. As you may notice this implementation is not flexible. What if the size of array grows? We add more values in Math.max argument. As a developer we didn’t want to do that we do hard code (...)