Ask coding questions

← Back to all posts
I can't find the Max number with this simple route function, help
nanasv (0)

</>
const mixItems = ["58","50","1000","53"];
//filter function call

//filter function
let maxValSearch = [];
maxValSearch = [...mixItems];

function eventHandler(par){
return par.map(function(el){
if(parseInt(el)){
maxValSearch = el;
return maxValSearch.indexOf(Math.max([... maxValSearch]));
}
//i just need the max balue, 1000, out

});
}
console.log(eventHandler(mixItems));
</>

Comments
hotnewtop
Bookie0 (5969)

Can't you just use Math.max()? Read more here

And look at the following code for finding the max number in an array (dunno the source, from Grepper):

// For large data, it's better to use reduce. Supose arr has a large data in this case:
const arr = [1, 5, 3, 5, 2];
const max = arr.reduce((a, b) => { return Math.max(a, b) });

// For arrays with relatively few elements you can use apply: 
const max = Math.max.apply(null, arr);

// or spread operator:
const max = Math.max(...arr);
nanasv (0)

@Bookie0
Thanks, but notice that my integers are in the string. Now if i try to use Math.max method the result appear null to each index.
Why i my using string integer, basically i was trying to find the max number in a array of string where integers where mixed with characters. Eg arr "cloths","48",etc. I was not finding it easy then i have to move on with just int in a string.

Bookie0 (5969)

sorry not very sure about this JS @nanasv

Bookie0 (5969)

You could try to ask in the repl.it discord server here if you want! :) @nanasv

nanasv (0)

@Bookie0
Ok then thanks.
But did you have idea on .env and how to call its variables to node.server

Bookie0 (5969)

@nanasv wdym? Btw, I'm not very experienced with node servers, but you can use .env files in your program.

nanasv (0)

@Bookie0
yeah, am specific about the set up. Am currently solving fcc Apis an microservices. Sorry which language did you specialize

Bookie0 (5969)

@nanasv uh ok. i mostly do Python, but know some HTML CSS JS

nanasv (0)

@Bookie0
Ok, i understand
an i do js and much on html,css