JSFiddle - React, Tailwind, and code Playground

by Anastasia Sharko

JavaScript

function isFalsy(value){
    return !value;
}
function isTruthy(value){
    return !!value;
}
var truthyCriteria =  [isFalsy, isTruthy];
var groupArray = function(array) {
    return truthyCriteria.map(function(criteriaFunction) {
        return array.filter(criteriaFunction);
    })
};
groupArray([1,2,3,0,'', null, 1, undefined]);
document.body.textContent = groupArray([1,2,3,0,'', null, 1, undefined]).join(';');
//null, '', undetifined в документе приводитк пустому
// оставить больше двух и меньше двух
function isLessTwo(value){
    return value < 2;
}
function isMoreTwo(value){
    return value >= 2;
}
var truthyCriteria =  [isLessTwo, isMoreTwo];
var groupArray = function(array) {
    return truthyCriteria.map(function(criteriaFunction) {
        return array.filter(criteriaFunction);
    })
};
groupArray([1,2,3,0,'', null, 1, undefined]);
document.body.textContent = groupArray([1,2,3,0,'', null, 1, undefined]).join(';');