请你编写一段代码实现一个数组方法,使任何数组都可以调用 array.last() 方法,这个方法将返回数组最后一个元素。如果数组中没有元素,则返回 -1 。

ps:this 环境变量的使用 ,this.length 的返回值是数字类型

代码实现:

 <script>
//在数组的原型写扩展方法可以给所有的数组一起使用
Array.prototype.last = function() {
if(this.length === 0) return -1
return this[this.length - 1]
}; const arr = []
const a = arr.last()
console.log(a) </script>

7-11 leetcode 2619的更多相关文章

  1. 11. leetcode 283. Move Zeroes

    Given an array nums, write a function to move all 0's to the end of it while maintaining the relativ ...

  2. [LintCode] Divide Two Integers 两数相除

    Divide two integers without using multiplication, division and mod operator. If it is overflow, retu ...

  3. 地区sql

    /*Navicat MySQL Data Transfer Source Server : localhostSource Server Version : 50136Source Host : lo ...

  4. LeetCode 11. Container With Most Water (装最多水的容器)

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai).  ...

  5. 2017/11/22 Leetcode 日记

    2017/11/22 Leetcode 日记 136. Single Number Given an array of integers, every element appears twice ex ...

  6. 2017/11/21 Leetcode 日记

    2017/11/21 Leetcode 日记 496. Next Greater Element I You are given two arrays (without duplicates) num ...

  7. 2017/11/13 Leetcode 日记

    2017/11/13 Leetcode 日记 463. Island Perimeter You are given a map in form of a two-dimensional intege ...

  8. 2017/11/20 Leetcode 日记

    2017/11/14 Leetcode 日记 442. Find All Duplicates in an Array Given an array of integers, 1 ≤ a[i] ≤ n ...

  9. 2017/11/9 Leetcode 日记

    2017/11/9 Leetcode 日记 566. Reshape the Matrix In MATLAB, there is a very useful function called 'res ...

  10. 2017/11/7 Leetcode 日记

    2017/11/7 Leetcode 日记 669. Trim a Binary Search Tree Given a binary search tree and the lowest and h ...

随机推荐

  1. 【Docker】09 部署挂载本地目录的Redis

    1.拉取Redis镜像: docker pull redis:6.0.6 2.执行挂载命令: docker run -d \ --name=redis \ --restart=always \ --p ...

  2. A3C与GA3C的收敛性分析

    G-A3C的代码: https://gitee.com/devilmaycry812839668/gpu_a3c 论文: <Reinforcement Learning thorugh Asyn ...

  3. 再探 游戏 《 2048 》 —— AI方法—— 缘起、缘灭(5) —— 第一个用于解决2048游戏的Reinforcement learning方法——《Temporal Difference Learning of N-Tuple Networks for the Game 2048》

    <2048>游戏在线试玩地址: https://play2048.co/ 如何解决<2048>游戏源于外网的一个讨论帖子,而这个帖子则是讨论如何解决该游戏的最早开始,可谓是&q ...

  4. 暑假Java自学进度总结05

    一.今日所学: 1.if的第一个表达式: if(关系表达式){ 语句: } 执行流程: 1>首先执行关系表达式的值 2>如果关系表达式的值为true则执行语句,否则不执行 3>继续执 ...

  5. 最短小精悍的js数组打乱顺序

          let number = [1, 45, 13, 17];       // 封装一个打乱数组的方法       function getarr(arr) {         return ...

  6. 执行maven时报内存溢出OutOfMemory

    解决的方法是调整java的堆大小的值. Windows环境中 找到文件%M2_HOME%\bin\mvn.bat ,这就是启动Maven的脚本文件,在该文件中你能看到有一行注释为: @REM set ...

  7. Win32 滚动条控件

    1.创建控件 HWND hScrollBar = ::CreateWindow( WC_SCROLLBAR,                           //控件类名 NULL,        ...

  8. Linux 常见编辑器

    命令行编辑器 Vim Linux 上最出名的编辑器当属 Vim 了.Vim 由 Vi 发展而来,Vim 的名字意指 Vi IMproved,表示 Vi 的升级版.Vim 对于新手来说使用比较复杂,不过 ...

  9. How to set keyboard for xshell 8 beta? 快捷键设置

    今天发现xshell8 不能使用Ctrl + v,就找了一下攻略,发现版本不对,都是低版本的,针对还处于测试期间的xshell 8,没有攻略. 那就自己摸索吧,看了几眼,发现:xshell 8 挪位置 ...

  10. Docker学习系列3:常用命令之容器命令

    本文是Docker学习系列教程中的第三篇.前几篇教程如下: 「图文教程」Windows11下安装Docker Desktop 「填坑」在windows系统下安装Docker Desktop后迁移镜像位 ...