We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7372049 commit d6d9811Copy full SHA for d6d9811
2619. array-prototype-last/README.md
@@ -0,0 +1,6 @@
1
+```mermaid
2
+flowchart TD
3
+ A(Start) --> B{Is array empty?}
4
+ B -- No --> C(Return last element)
5
+ B -- Yes --> D(Return -1)
6
+```
2619. array-prototype-last/index.js
@@ -1,9 +1,3 @@
Array.prototype.last = function () {
- if (this[this.length - 1] === null) {
- return null;
- }
- if (this[this.length - 1] === undefined) {
- return -1;
7
8
- return this[this.length - 1];
9
-};
+ return this.length === 0 ? -1 : this[this.length - 1]
+}
0 commit comments