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 ...
随机推荐
- Jmeter函数助手34-digest
digest函数用于返回特定哈希算法的加密值. 算法摘要:填入算法,如MD2.MD5.SHA-1.SHA-224.SHA-256.SHA-384.SHA-512 String to be hashed ...
- NVIDIA人形机器人AI套件:NVIDIA Isaac Manipulator 和 NVIDIA Isaac Perceptor
IsaacManipulator 为机械臂提供了卓越的灵活性和模块化AI功能,并提供了一系列强大的基础模型和GPU加速库.它提供了高达80倍的路径规划加速,零样本感知提高了效率和吞吐量,使开发者能够实 ...
- 使用触发器来审计表的DML、DDL操作
最近帮客户排查某问题时,因为怀疑应用对某张配置表有变更,所以需要对这张表的所有操作进行审计. 原本Oracle对某张表的审计是非常方便的,一条命令就可以实现,也不需要费心自定义审计表. -- 启用对表 ...
- 面试官:JDK中都用了哪些设计模式?
设计模式是前辈们经过实践验证总结的解决方案,帮助我们构建出更具可维护性.可扩展性和可读性的代码.当然,在面试的过程中,也会或多或少的被问到.那么今天,我们就来看一道设计模式中的常见面试问题:JDK 中 ...
- 信创环境:鲲鹏ARM+麒麟V10离线部署K8s和Rainbond信创平台
在上篇<国产化信创开源云原生平台>文章中,我们介绍了 Rainbond 作为可能是国内首个开源国产化信创平台,在支持国产化和信创方面的能力,并简要介绍了如何在国产化信创环境中在线部署 Ku ...
- 禅道项目管理系统权限绕过漏洞(QVD-2024-15263)
本文所涉及的任何技术.信息或工具,仅供学习和参考之用,请勿将文章内的相关技术用于非法目的,如有相关非法行为与文章作者无关.请遵守<中华人民共和国网络安全法>. 1. 概述 1.1 基本信息 ...
- SNMP基础概念
一.什么是SNMP? SNMP=Simple Network Management Protocol (简单网络管理协议) SNMP是被广泛接受并投入使用的工业标准,提供了一个框架来定义管理信 ...
- Ubuntu 24.04 安装 Python 2.7
Ubuntu 24.04 对 Python 2.7 的维护已经停止了,因此 Python 2.7 已从 Ubuntu 24.04 软件包移除.如果想要安装 Python 2.7,需要我们自己从 Pyt ...
- 图文教程:从0到1将项目发布到 Maven 中央仓库
前言 本文基于官方文档 https://central.sonatype.org/publish/publish-guide/ 编写. 发布步骤: 创建账号 创建用户 Token 创建命名空间 配置 ...
- spark 先groupby 再从每个group里面选top n
import spark.implicits._ val simpleData = Seq(("James","Sales","NY",90 ...