function closest(num, arr) {
    let curr = arr[0];
    let diff = Math.abs(num - curr);
    for (let val = 0; val < arr.length; val++) {
        let newdiff = Math.abs(num - arr[val]);
        if (newdiff < diff) {
            diff = newdiff;
            curr = arr[val];
        }
    }
    return curr;
}
// Detect the closest number from array of numbers
Detect the closest number from array of numbers
Detect the closest number from array of numbers
function closest(num, arr) {
    let curr = arr[0];
    let diff = Math.abs(num - curr);
    for (let val = 0; val < arr.length; val++) {
        let newdiff = Math.abs(num - arr[val]);
        if (newdiff < diff) {
            diff = newdiff;
            curr = arr[val];
        }
    }
    return curr;
}
function closest ( num , arr ) { let curr = arr [ 0 ] ; let diff = Math . abs ( num - curr ) ; for ( let val = 0 ; val < arr . length ; val ++ ) { let newdiff = Math . abs ( num - arr [ val ] ) ; if ( newdiff < diff ) { diff = newdiff ; curr = arr [ val ] ; } } return curr ; }
Detect the closest number from array of numbers
Detect the closest number from array of numbers