Okay, my thirst for terrible oneliners is not exhausted yet ..
I have < / P>
var a = "2: 3: 9: 5";
I want to find the largest number and its index
In this case: 9
and index 2
.
What is the complex and terrible way to do this?
I tried:
var _number = Math.max.apply (Math, a.split (':'));
try it
var a = "2 : 3: 9: 5 "; Var arr = a.split (":"); Var max = Math.max.apply (empty, arr); Var index = arr.indexOf (max.toString ());
No comments:
Post a Comment