-2

Below is the array:

largestNumber([1,19,[3,7],16,[19,27,12],13,11]);

I am trying to find the max value using Javascript function but not getting the solution.

Anyone could help me to get the solution.

Thanks in advance.

  • Define "trying". Where's your current code that is failing to do what you want? –  May 12 '18 at 15:18
  • @Jonas: How do you figure that question is asking the same thing as this one? –  May 12 '18 at 15:29
  • 1
    @crazy Train the OP has shown no effort whatsoever, i gave him a good starting point. – Jonas Wilms May 12 '18 at 15:30
  • 1
    There are probably thousands of solutions for this, its a common codegolf / codewars task – Jonas Wilms May 12 '18 at 15:30
  • @JonasW.: I agree that no effort is shown and IMO, it should be closed. That doesn't make it a duplicate. –  May 12 '18 at 15:31
  • @crazy train it takes longer to get 10 closevotes for "unclear what you are asking", which gives people enough time to answer... – Jonas Wilms May 12 '18 at 15:32
  • @JonasW.: It doesn't take 10 votes. Yeah, he's abusing the site, but aren't you also by using an invalid reason for closing? –  May 12 '18 at 15:34
  • @crazy train close votes are totally democratic :) if you disagree, you can vote to reopen ... – Jonas Wilms May 12 '18 at 15:36
  • @JonasW.: You're subverting the democratic nature of close votes by imposing an invalid reason for closing. –  May 12 '18 at 15:37
  • ...funny thing is that you're complaining that the OP showed no effort, but neither did you. There are may valid duplicates if you'd only use the same Google search that the OP ought to have used. –  May 12 '18 at 15:39

1 Answers1

1

You can do this with Math.max and spread syntax ...

const largestNumber = arr => Math.max(...[].concat(...arr));
console.log(largestNumber([1,19,[3,7],16,[19,27,12],13,11]))
Nenad Vracar
  • 118,580
  • 15
  • 151
  • 176