JSFiddle - React, Tailwind, and code Playground

by Eluro

HTML

<body>
<h1 id="someId">
</h1>
</body>

JavaScript

var AbstractFilter = function() {
            this.nextAbstractFilter = null;
            this.setNext = function(next) {
                this.nextAbstractFilter = next;
            }
            this.filter = function(entries) {
                throw new Error("You should implement this abstract method!");
            }
            this.filterAll = function(entries) {
                var filteredEntries = this.filter(entries);

                if (this.nextAbstractFilter) {
                    filteredEntries = this.nextAbstractFilter.filterAll(filteredEntries);
                }

                return filteredEntries;
            }
        };

        function mainFilter(entries) {
            var f2 = new AbstractFilter();
            f2.filter = function(entries) {
                return _.filter(entries, function(entry) {
                    return (entry % 2 != 0);//Quita pares
                });
            };

            var f3 = new AbstractFilter();
            f3.filter = function(entries) {
                return _.filter(entries, function(entry) {
                    return (entry % 3 != 0); //Quita mod 3
                });
            };

            var f5 = new AbstractFilter();
            f5.filter = function(entries) {
                return _.filter(entries, function(entry) {
                    return (entry % 5 != 0); // Quita mod 5
                });
            };

            f3.setNext(f5);
            f2.setNext(f3);

            return f2.filterAll(entries);
        }


var list = [1,2,3,4,5,6,7,8,9,10];
var flist = mainFilter(list);

var h1 = document.getElementById("someId");
h1.text = flist.toString();