💾arr.none()
// ⭐️ arrow function
const none = (arr, callback) => !arr.some(callback);
// ⭐️ regular function
function none2(arr, callback){ return !arr.some(callback); }
// ⭐️ method 1
Object.defineProperty(Array.prototype, 'none3', {
value: function (callback) { return !this.some(callback) }
});
// ⭐️ method 2
Array.prototype.none4 = function(callback){
return !this.some(callback)
};
💈範例:
const { log } = console;
let arr = ["a","b","c"];
[
none(arr, x => x === "b"), // false
none(arr, x => x === "x"), // true
none2(arr, x => x === "b"),
none2(arr, x => x === "x"),
arr.none3(x => x === "b"),
arr.none3(x => x === "x"),
arr.none4(x => x === "b"),
arr.none4(x => x === "x"),
].forEach(x => log(x));
Last updated