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 ...
随机推荐
- Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was 14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的错误"解决yum下载报错
报错信息 │ (SSH client, X server and network tools) │ │ │ │ ⮞ SSH session to root@192.168.117.166 │ │ • ...
- 【SpringBoot】11 Web开发 Part2 模板引擎
开发回顾: JavaWeb开发使用JSP技术,所有的页面文件必须是JSP,才能接受数据处理 JSP的好处是,数据交互方便,有JSTL补充 SpringBoot的区别: 我们最终的项目是一个jar包 内 ...
- 【JS】06 语法补充
严格模式(use strict) 其实就是就是对JS随意的语法做一个强制规范要求 开启严格模式: "use strict"; 注意,只有在第一行声明才会有效,. 否则在严格模式之前 ...
- 【Spring Data JPA】10 对象导航查询
定义: 查询一个记录时,也就是查询这个对象,通过这个对象查询他的关联对象 [说白了不就是从我们设置好的集合中获取不就完了吗] 环境搭建: INSERT INTO `jpa`.`cst_customer ...
- pytorch的显存释放机制torch.cuda.empty_cache()
参考: https://cloud.tencent.com/developer/article/1626387 据说在pytorch中使用torch.cuda.empty_cache()可以释放缓存空 ...
- NVIDIA公司的半成品项目cule——GPU端运行的Atari2600游戏环境——已经废弃的项目
官网介绍地址: https://developer.nvidia.com/blog/new-open-source-gpu-accelerated-atari-emulator-for-reinfor ...
- JAVA集合专题之深入学习
1.背景 集合虽然用起来非常简单... 但是面试确问得很多,很深.... 最重要的是集合的设计里面使用了大量的非常典型的多线程设计... 如果能把集合中的源码学一遍,相信你的多线程功底会大大提升... ...
- Temperature 题解
前言 题目链接:洛谷:SPOJ:Hydro & bzoj. 题意简述 有一个长度为 \(n\) 的序列,每个位置值的范围为 \([L_i, R_i]\) 内,求原序列可能的最长不降子串长度. ...
- double四舍五入保留两位小数的方法
1,DecimalFormat DecimalFormat decimalFormat = new DecimalFormat(".00"); 意思就是规定保留几位小数 使用时 d ...
- 最短小精悍的js数组打乱顺序
let number = [1, 45, 13, 17]; // 封装一个打乱数组的方法 function getarr(arr) { return ...