util: Removed delete* util methods, added Array.prototype.remove

This commit is contained in:
warp03 2023-04-10 16:00:49 +02:00
parent 88572f2547
commit 9f349a556d
Signed by: warp03
GPG Key ID: B6D2AC20BD3262DA

16
util.js

@ -30,12 +30,16 @@ module.exports.initPrototypes = () => {
return this.slice(0, index) + str + this.slice(index);
};
String.prototype.deleteCharAt = function(index){
return this.slice(0, index) + this.slice(index + 1);
};
Array.prototype.deleteElementAt = function(index){
return this.splice(index, 1);
Array.prototype.remove = function(element, compareFunc = (a, b) => a == b){
let removed = 0;
for(let i = 0; i < this.length; i++){
if(compareFunc(this[i], element)){
this.splice(i, 1);
i--;
removed++;
}
}
return removed;
};
const fs = require("fs");