kvnallen
6/16/2017 - 12:14 AM

Curso JS Funcional (Suissa)

Curso JS Funcional (Suissa)

const allNumbers = [ 'LOL', 1, -1, 2, -3, -5, 7, 9, 10, 0.33333, 0]
let positiveCount = 0;
let negativeCount = 0;

allNumbers.forEach(function(number) {
    
    if(isNaN(number))
        return;
    if(number > 0)
        positiveCount++;
    else if(number < 0)
        negativeCount++;
    
}, this);
const allNumbers = [ 'LOL', 1, -1, 2, -3, -5, 7, 9, 10, 0.33333, 0]
const NOT = ( x ) => !x

const isValidNumber = ( number ) => NOT( isNaN ( number ) )
const isPositive = ( number ) => isValidNumber( number ) && number && number > 0
const isNegative = ( number ) => isValidNumber( number ) && NOT( isPositive( number ) )

const positiveCount = allNumbers.filter( isPositive ).length
const negativeCount = allNumbers.filter( isNegative ).length