请你编写一段代码实现一个数组方法,使任何数组都可以调用 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. 使用AWS存储数据并下载遥感影像Landsat为例

    使用AWS存储数据并下载遥感影像Landsat为例 一.步骤: 创建s3存储桶(具体创建账号方式请问"度娘",当时忘记录了) 创建用户--配置策略 用该用户创建访问密钥--记录 访 ...

  2. SEO自动外链工具的功效以及使用心得

    SEO外链发布工具原理 1.自动SEO外链工具原理:就是把您的网址提交大站长工具类似的网站上面进行搜索,然后就会在上面留下痕迹自动生成以网址为标题的静态页面. 2.自动SEO外链发布效果:我们就是利用 ...

  3. JavaWeb入门到实战学习笔记

    了解,讲得并不是很好,很展开. 概念 动态web Web服务器 web服务器这节也是蜻蜓点水,引出tomcat而已 ASP(C#语言,微软) JSP PHP Java bootstrapclasslo ...

  4. Jenkins API用户认证方式

    1.概述 Jenkins的API可以通过用户名+密码或者用户名+Token的方式来进行认证,这篇文章以具体示例来说明具体的使用方式. 2.Jenkins环境 本文示例基于Jenkins 2.452.3 ...

  5. Ubuntu 18.04.4 安装docker18.09 (使用阿里云的源)

    由于AI_Station 是使用容器构建环境的,而且只提供镜像上传下载功能,不为容易提供网络功能,因此需要在平台上把镜像拉取到本地,并安装一些必备软件然后再打包成镜像上传回去,因此需要在本地构建doc ...

  6. Salesforce Sales Cloud 零基础学习(五) My Labels的使用

    本篇参考: https://help.salesforce.com/s/articleView?id=sf.sales_core_record_labels.htm&type=5 在公司中,S ...

  7. 系统IO常用函数接口

    本文整理归纳了几种常用的系统IO的函数借口,以供读者查阅使用 目录 系统IO与标准IO的区别 打开文件:open 关闭文件:close 文件读取:read 文件写入:write 位置偏移:lseek ...

  8. Linux input 子系统详解

    1. 模块概述 1.1.相关资料和代码研究 drivers/input/ include/uapi/linux/input-event-codes.h 2. 模块功能 linux核心的输入框架 3. ...

  9. 零基础学习人工智能—Python—Pytorch学习(五)

    前言 上文有一些文字打错了,已经进行了修正. 本文主要介绍训练模型和使用模型预测数据,本文使用了一些numpy与tensor的转换,忘记的可以第二课的基础一起看. 线性回归 结合numpy使用 首先使 ...

  10. 单例模式C++实现

    单例模式 全局静态变量实现饿汉式单例模式 饿汉式实现方式是线程安全的. #include using namespace std; /* 饿汉式单例模式 */ class SingleObject{ ...