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 ...
随机推荐
- 【Java】图片上传逻辑
后台逻辑: 后台服务,用Dubbo框架作为一个文件微服务 package cn.ymcd.aisw.service; import cn.ymcd.aisw.dto.RpcResult; /** * ...
- 【SpringMVC】05 RestFul风格
什么是RestFul风格? 一个资源定位和资源操作的风格,不是标准,也不是协议, 基于此风格的路径访问可以隐藏真实的参数传递,以提高网站的安全访问 以往的请求参数: jdbc:mysql://loca ...
- 【Linux】Re03
一.软连接 语法用法 ln -s 源文件或者目录位置 链接名称 [root@localhost ~]# mkdir -p aa/bb/cc/dd [root@localhost ~]# ln -s a ...
- 【Java,IDEA】创建自己的代码模版快速生成
写原生JavaWeb发现一个问题就是声明方法的时候没有字符关联提示, 只能一个保留字,一个保留字这样单个的敲出来方法,写多了就会发现特别费劲 当遇上一个字特别多且经常需要声明的方法可以使用IDEA的生 ...
- python报错:ImportError: cannot import name 'Literal' from 'typing'
原因: Literal 只支持python3.8版本以上的环境,需要把python3.7升级到3.8版本以上. 参考: https://blog.csdn.net/yuhaix/article/det ...
- baselines算法库logger.py模块分析
baselines根目录下logger.py模块代码: import os import sys import shutil import os.path as osp import json imp ...
- OpenTiny HUICharts开源发布,带你了解一个简单、易上手的图表组件库
摘要:目前 OpenTiny HUICharts 已经成功落地在华为内部100多个产品中,持续提升了用户的可视化体验. 本文分享自华为云社区<OpenTiny HUICharts 正式开源发布, ...
- Python 潮流周刊#64:Python 的函数调用还很慢么?(摘要)
本周刊由 Python猫 出品,精心筛选国内外的 250+ 信息源,为你挑选最值得分享的文章.教程.开源项目.软件工具.播客和视频.热门话题等内容.愿景:帮助所有读者精进 Python 技术,并增长职 ...
- RISC-V全志D1多媒体套件文章汇总
提示 此开发板的任何问题都可以在我们的论坛交流讨论 https://forums.100ask.net/c/aw/d1/57 文章目录汇总 教程共计14章,下面是章节汇总: 第0章_RISC-V全志D ...
- Docker 容器中镜像导出/导入
目录 [容器]镜像导出/导入 导出 导入 带标签 不带标签,后期修改 [仓库]镜像导出/导入 导出 导入 导入(完整命令) 创建一个简单的Docker镜像 利用docker ps -a命令查看要导出的 ...