Answer by sporkl for Smallest number in array and its position
Find the smallest value using Math.min and the spread operator:var minimumValue = Math.min(...temp);Then find the index using indexOf:var minimumValueIndex = temp.indexOf(minimumValue);I personally...
View ArticleAnswer by Apollo for Smallest number in array and its position
You could use reduce, and compare against Infinity.let minIndex = -1;arr.reduce((acc, curr, index) => { if (curr < acc) { minIndex = index; return curr; } else { return acc; }}, Infinity);
View ArticleAnswer by EugenSunic for Smallest number in array and its position
Here is a solution using simple recursion. The output is an object containing the index position of the min number and the min number itselfconst findMinIndex = (arr, min, minIndex, i) => { if...
View ArticleAnswer by Raku Zeta for Smallest number in array and its position
See this answer of "find max" version of this question. It is simple and good. You can use the index to get the element afterward.
View ArticleAnswer by Tony for Smallest number in array and its position
One-liner:alist=[5,6,3,8,2]idx=alist.indexOf(Math.min.apply(null,alist))
View ArticleAnswer by MattDiamant for Smallest number in array and its position
You want to use indexOfhttp://www.w3schools.com/jsref/jsref_indexof_array.aspUsing the code that you had before, from the other question:temp = new Array();temp[0] = 43;temp[1] = 3;temp[2] =...
View ArticleAnswer by Guffa for Smallest number in array and its position
Just loop through the array and look for the lowest number:var index = 0;var value = temp[0];for (var i = 1; i < temp.length; i++) { if (temp[i] < value) { value = temp[i]; index = i; }}Now value...
View ArticleSmallest number in array and its position
What I am trying to achieve is to find smallest number in array and its initial position. Here's an example what it should do:temp = new Array();temp[0] = 43;temp[1] = 3;temp[2] = 23;So in the end I...
View Article
More Pages to Explore .....