lib/split-arc.js
function closestButNotGreaterThan(numbers, maxNumber) {
    var positiveNumbers = numbers.map(function(number){
        return Math.abs(number);
    });
    var positiveMaxNumber = Math.abs(maxNumber);

    var winner = positiveMaxNumber;
    var winningDifference = positiveMaxNumber;

    for (var i=0; i < positiveNumbers.length; i++) {
        var lessThanMax = positiveNumbers[i] <= positiveMaxNumber;
        var closerToMax = (positiveMaxNumber - positiveNumbers[i]) < winningDifference;
        if (lessThanMax && closerToMax) {
            winner = positiveNumbers[i];
            winningDifference = positiveMaxNumber-positiveNumbers[i];
        }
    }
    return winner;
}
function closestButNotGreaterThan(numbers, maxNumber) {
    var positiveNumbers = numbers.map(function(number){
        return Math.abs(number);
    });
    var positiveMaxNumber = Math.abs(maxNumber);

    var winner = positiveMaxNumber;
    var winningDifference = positiveMaxNumber;

    for (var i=0; i < positiveNumbers.length; i++) {
        var lessThanMax = positiveNumbers[i] <= positiveMaxNumber;
        var closerToMax = (positiveMaxNumber - positiveNumbers[i]) < winningDifference;
        if (lessThanMax && closerToMax) {
            winner = positiveNumbers[i];
            winningDifference = positiveMaxNumber-positiveNumbers[i];
        }
    }
    return winner;
}
function closestButNotGreaterThan ( numbers , maxNumber ) { var positiveNumbers = numbers . map ( function ( number ) { return Math . abs ( number ) ; } ) ; var positiveMaxNumber = Math . abs ( maxNumber ) ; var winner = positiveMaxNumber ; var winningDifference = positiveMaxNumber ; for ( var i = 0 ; i < positiveNumbers . length ; i ++ ) { var lessThanMax = positiveNumbers [ i ] <= positiveMaxNumber ; var closerToMax = ( positiveMaxNumber - positiveNumbers [ i ] ) < winningDifference ; if ( lessThanMax && closerToMax ) { winner = positiveNumbers [ i ] ; winningDifference = positiveMaxNumber - positiveNumbers [ i ] ; } } return winner ; }
Return number with closest absolute value to maxNumber without exceeding it
Return number with closest absolute value to maxNumber without exceeding it