7-11 leetcode 2619
请你编写一段代码实现一个数组方法,使任何数组都可以调用 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的更多相关文章
- 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 ...
- [LintCode] Divide Two Integers 两数相除
Divide two integers without using multiplication, division and mod operator. If it is overflow, retu ...
- 地区sql
/*Navicat MySQL Data Transfer Source Server : localhostSource Server Version : 50136Source Host : lo ...
- LeetCode 11. Container With Most Water (装最多水的容器)
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- 2017/11/22 Leetcode 日记
2017/11/22 Leetcode 日记 136. Single Number Given an array of integers, every element appears twice ex ...
- 2017/11/21 Leetcode 日记
2017/11/21 Leetcode 日记 496. Next Greater Element I You are given two arrays (without duplicates) num ...
- 2017/11/13 Leetcode 日记
2017/11/13 Leetcode 日记 463. Island Perimeter You are given a map in form of a two-dimensional intege ...
- 2017/11/20 Leetcode 日记
2017/11/14 Leetcode 日记 442. Find All Duplicates in an Array Given an array of integers, 1 ≤ a[i] ≤ n ...
- 2017/11/9 Leetcode 日记
2017/11/9 Leetcode 日记 566. Reshape the Matrix In MATLAB, there is a very useful function called 'res ...
- 2017/11/7 Leetcode 日记
2017/11/7 Leetcode 日记 669. Trim a Binary Search Tree Given a binary search tree and the lowest and h ...
随机推荐
- 【MySQL】重装Win10系统后恢复MySQL
因为种种原因把系统重装了,安装的MySQL不在C盘中,所以数据不会被系统格式化掉 但是重装系统就把之前CMD声明的MySQL服务给删除了 要让MySQL重新跑起来,就需要重新安装服务 恢复MYSQL博 ...
- 【Linux】11 RPM & YUM 管理工具 介绍
rpm包的管理 介绍: 一种用于互联网下载包的打包及安装工具,它包含在某些Linux分发版中. 它生成具有.RPM扩展名的文件.RPM是RedHat Package Manager(RedHat软件包 ...
- 绝对要收藏!!! JavaEE开发常用注解
目录 前言 1.Mybatis常用注解 2.SpringMVC常用注解 3.Spring常用注解 1. IoC注解 2. DI注解 3. 事务注解 4.SpringBoot常用注解 5.Lombok注 ...
- 【转载】 日内瓦大学 & NeurIPS 2020 | 在强化学习中动态分配有限的内存资源
原文地址: https://hub.baai.ac.cn/view/4029 ======================================================== [论文标 ...
- mybatis-plus详细的图文教程(含视频讲解)
1.课程大纲 2.目录链接 1.简介与CRUD快速使用 https://www.cnblogs.com/newAndHui/p/13938754.html 2.注解的使用 https://www.cn ...
- ApacheCon Asia 2022 精彩回顾 | 如何让更多人从大数据中获益?
点亮 ️ Star · 照亮开源之路 GitHub:https://github.com/apache/dolphinscheduler 在 ApacheCon Asia 2022 Meetup上,有 ...
- SMU Autumn 2023 Round 3(Div.1)
SMU Autumn 2023 Round 3(Div.1) A. Find The Array 要满足"b数组内任意一个元素满足可以被数组两边的元素整除"这个条件,我们很容易想到 ...
- 为什么要加 REQUIRE8 and PRESERVE8? 栈的8字节对齐
REQUIRE8 and PRESERVE8 The REQUIRE8 and PRESERVE8 directives specify that the current file require ...
- Mac安装Adobe PS_AE_PR等系列软件提示错误代码146怎么办?
在安装Mac版Adobe系列软件的时候,不管PS.AE.PR.AI等,如果出现错误代码146,下面两个方法能够轻松解决. 解决方法一:需要我们打开「系统设置」-「隐私与安全」-「App管理」,打开「i ...
- 网络安全公开数据集Maple-IDS,恶意流量检测数据集开放使用!
Maple Dataset 枫叶数据集Maple Dataset枫叶数据集由东北林业大学网络安全实验室(https://maple.nefu.edu.cn/lab/)公开发布,是用于入侵检测评估的数据 ...