Skip to content

Commit d6d9811

Browse files
committed
refactor: change logic & show flowchart
1 parent 7372049 commit d6d9811

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

2619. array-prototype-last/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
Array.prototype.last = function () {
2-
if (this[this.length - 1] === null) {
3-
return null;
4-
}
5-
if (this[this.length - 1] === undefined) {
6-
return -1;
7-
}
8-
return this[this.length - 1];
9-
};
2+
return this.length === 0 ? -1 : this[this.length - 1]
3+
}

0 commit comments

Comments
 (0)