<commit_before>com.magadanski.DOMCollection;

//////////////////////////////////////////
// DOMCollection Class Implementation ////
//////////////////////////////////////////
(function () {
	// import class
	var that;
	
	var DOMCollection = function (selector) {
		that = this;
		that.elements = [];
		
		var selection = null;
		
		if (typeof(selector) == 'string') {
			selection = document.querySelectorAll(selector);
		} else if (typeof(selector) == 'object') { // support to pass a result of querySelectorAll or similar
			selection = selector;
		} else {
			selection = false;
		}
		
		if (!!selection) {
			for (var i = 0; i < selection.length; i++) {
				that.elements.push(selection.item(i));
			}
		}
	}
	com.magadanski.DOMCollection = DOMCollection;
	
	// private properties
	
	// private methods
	
	// public methods
	DOMCollection.prototype.addEventListener = function (eventType, callback) {
		for (e in this.elements) {
			this.elements[e].addEventListener(eventType, callback);
		}
	}
	
	DOMCollection.prototype.removeEventListener = function (eventType, eventObj) {
		for (e in this.elements) {
			this.elements[e].removeEventListener(eventType, callback);
		}
	}
	
	DOMCollection.prototype.addClass = function (className) {
		for (e in this.elements) {
			this.elements[e].classList.add(className);
		}
	}
	
	DOMCollection.prototype.removeClass = function (className) {
		for (e in this.elements) {
			this.elements[e].classList.remove(className);
		}
	}
	
	DOMCollection.prototype.each = function (callback) {
		for (e in this.elements) {
			callback(e, this.elements[e]);
		}
	}
	
	DOMCollection.prototype.filter = function (selector) {
		var filteredElements = new DOMCollection();
		
		for (e in this.elements) {
			if (this.elements[e].matches(selector)) {
				filteredElements.elements.push(this.elements[e]);
			}
		}
		
		return filteredElements;
	}
})();
<commit_msg>refactoring and new functions for DOMCollection<commit_after>com.magadanski.DOMCollection;

//////////////////////////////////////////
// DOMCollection Class Implementation ////
//////////////////////////////////////////
(function () {
	// import class
	var that;
	
	var DOMCollection = function (selector, context) {
		that = this;
		that.elements = [];
		
		var selection = null;
		var callFunction = 'querySelectorAll';
		
		if (context instanceof HTMLElement) {
			// all OK -- no need to do anything
		} else if (context instanceof DOMCollection) {
			callFunction = 'find';
		} else {
			context = document;
		}
		
		if (typeof(selector) == 'string') {
			context[callFunction](selector);
		} else if (typeof(selector) == 'object') { // support to pass a result of querySelectorAll or similar
			selection = selector;
		} else {
			selection = false;
		}
		
		if (!!selection) {
			for (var i = 0; i < selection.length; i++) {
				that.elements.push(selection.item(i));
			}
		}
	}
	com.magadanski.DOMCollection = DOMCollection;
	
	// private properties
	
	// private methods
	
	// public methods
	DOMCollection.prototype.addEventListener = function (eventType, callback) {
		this.elements.map(function (el) {
			el.addEventListener(eventType, callback);
		});
	}
	
	DOMCollection.prototype.removeEventListener = function (eventType, eventObj) {
		this.elements.map(function (el) {
			el.removeEventListener(eventType, callback);
		});
	}
	
	DOMCollection.prototype.addClass = function (className) {
		this.elements.map(function (el) {
			el.classList.add(className);
		});
	}
	
	DOMCollection.prototype.removeClass = function (className) {
		this.elements.map(function (el) {
			el.classList.remove(className);
		});
	}
	
	DOMCollection.prototype.each = function (callback) {
		this.elements.map(function (el, i) {
			callback(i, el);
		});
	}
	
	DOMCollection.prototype.filter = function (selector) {
		var filteredElements = new DOMCollection();
		
		this.elements.map(function (el) {
			if (el.matches(selector)) {
				filteredElements.elements.push(el);
			}
		});
		
		return filteredElements;
	}
	
	DOMCollection.prototype.find = function (selector) {
		var foundElements = new DOMCollection();
		
		this.elements.map(function (el) {
			foundElements.elements.concat(el.querySelectorAll(selector));
		});
		
		return foundElements;
	}
	
	DOMCollection.prototype.remove = function () {
		this.elements.map(function (el) {
			el.remove();
		});
	}
})();

{'fraction_non_alphanumeric': 0.1675080312069757, 'fraction_numerical': 0.0004589261128958238, 'mean_word_length': 3.0212177121771218, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '953829', 'n_tokens_mistral': 1465, 'n_tokens_neox': 1262, 'n_words': 277}