array.size.js and README.md

This commit is contained in:
KoroLion 2021-04-29 22:10:51 +03:00
commit f21719db80
2 changed files with 23 additions and 0 deletions

3
README.md Normal file
View File

@ -0,0 +1,3 @@
Solved tasks from:
http://rubaxa.github.io/playground/

20
array.size.js Normal file
View File

@ -0,0 +1,20 @@
// Реализоватьсвойство `size` у всех массивов,
// которое работало бы точно так же, как и `length`.
Object.defineProperty(
Array.prototype,
'size',
{
get: function () { return this.length; },
set: function (v) { this.length = v; }
}
);
// #1
console.log([0, 1].size); // 2
// #2
var arr = [0, 1, 2];
arr.size = 0;
console.log(arr); // []