// secondLargest([1, -2, 3]) = 1;
// secondLargest([5, 5, 4]) = 4;

// 1. Passed value not an Array:
// secondLargest("1 2 3") = undefined;

// 2. There is no second largest:
// secondLargest([2, 2, 2]) = undefined;

// 3. Array contain number strings:
// secondLargest([2, '3', 4]) = 3;

// 4. Array contain anything else:
// secondLargest(['-1', 2.01, null, false]) = -1;

function secondLargest( arr ){
    if ( Array.isArray(arr) ){
        arr = arr.filter( function (val){
                if( typeof val === 'string' ) return !Number.isNaN( val );
                if( typeof val === 'number' ) return true;

                return false;
            }).map( (val) => +val )
            .sort( (a,b) => b-a )
            .filter( (val, i, arr) => arr.indexOf(val) == i );

        return arr[1];
    }
}
@@ -442,13 +442,14 @@
     
-arr =
+return
  arr
@@ -473,16 +473,20 @@
  (val)%7B%0A
+    
         
@@ -560,35 +560,42 @@
                 
-if(
+    return
  typeof val === 
@@ -606,55 +606,33 @@
 ber'
- ) return true;%0A%0A                return false;%0A
+;%0A                %7D)%0A    
     
@@ -639,18 +639,16 @@
         
-%7D)
 .map( (v
@@ -673,16 +673,20 @@
         
+    
 .sort( (
@@ -711,16 +711,20 @@
         
+ 
+   
 .filter(
@@ -764,18 +764,16 @@
 ) == i )
-;%0A
 %0A       
@@ -773,26 +773,24 @@
         
-return arr
+        
 %5B1%5D;%0A   

Optimize secondLargest function