Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ArrayNb extends Array {
- constructor(props) {
- !!props ? super(props) : super();
- }
- push(...elements) {
- if ( [...elements].every(e => typeof e === "number") ){
- return super.push(...elements);
- } else {
- throw new Error("ArrayNb can only store numbers");
- }
- }
- populate(array) {
- if (Array.isArray(array)) {
- array.forEach(e => {
- this.push(e);
- })
- } else {
- throw new Error("ArrayNb.prototype.populate require an Array as argument");
- }
- }
- }
- const a = new Array();
- const anb = new ArrayNb();
- console.log(a);
- console.log(anb);
- console.log(a.push(3, 4));
- console.log(anb.push(3, 4));
- console.log(a)
- console.log(anb)
- console.log(a.join(''))
- console.log(anb.join(''))
- anb.populate([671,2,0]);
- console.log(anb)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement