no for & 100 Array & Uint8Array & Typed Arrays
no for & 100 Array
padStart
const arr = [...``.padStart(100, ` `)].map((item, i) => item = i+1);
const arr = ``;
const result = [...arr.padStart(100, "x")].map((x, i) => x = i+1);
console.log(`result =`, result);
// Array [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart
bad
function generate100Array() {
var arr = new Array(100);
for(var i = 0; i < 100; i++){
arr[i]='';
}
return arr;
}
var a = generate100Array(),
b = generate100Array();
console.time('for');
for (var i = 0; i < a.length; i++) {
a[i] = i;
}
console.timeEnd('for');
console.time('forEach');
b.forEach(function (el, index) {
b[index] = index;
});
console.timeEnd('forEach');
for
is better thanforEach
map
Array 100 & no for
https://stackoverflow.com/questions/22826953/how-to-create-array-of-100-with-integers-from-1-1000
https://jsperf.com/fast-array-foreach
Uint8Array
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array
https://en.wikipedia.org/wiki/Bit_array
https://stackoverflow.com/questions/29523206/how-do-i-write-an-8-bit-array-to-a-16-bit-array-of-1-2-size
https://stackoverflow.com/questions/33793246/c-converting-8-bit-values-into-16-bit-values
Typed Arrays
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
new_arr = new Uint8Array(100); // new in ES2017
// Uint8Array(100) [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
old_arr = new Array(100);
// (100) [empty × 100]
no for
& create Array 100
new Uint8Array(100).map((item, i) => (item = i));
// Uint8Array(100) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]
bitwise-operators
不用加减乘除运算符, 求整数的7倍
"use strict";
/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2019-08-15
*
* @description bitwise-operators
* @description 不用加减乘除运算符, 求整数的7倍
* @description 7 times, without multiplication
* @augments
* @example
* @link https://www.cnblogs.com/xgqfrms/p/11355923.html
*
*/
let log = console.log;
// 7 times, without multiplication
const autoSeventTimes = (num = 0, times = 7) => {
num = Math.abs(num);
let x = Math.floor(times / 2);
return (num << x) - num;
};
let xyz = autoSeventTimes(3);
// 21
console.log(`xyz =`, xyz);
no for & 100 Array & Uint8Array & Typed Arrays的更多相关文章
- Typed Arrays in javascripts
Typed Arrays(类型数组)这个概念,可能对很多人来说非常陌生,那么它是什么,又有什么用途呢? 之前的问题 Web应用程序变得越来越强大,例如新增了音视频处理.WebSocket等多个功能特性 ...
- js Array.from & Array.of All In One
js Array.from & Array.of All In One 数组生成器 Array.from The Array.from() static method creates a ne ...
- 5个 JS 解构有趣的用途
摘要: 玩转ES6解构赋值. 原文:5个 JS 解构有趣的用途 译者:前端小智 1. 交换变量 通常交换两个变量的方法需要一个额外的临时变量,来看看例子: let a = 1; let b = 2; ...
- 【前端】Util.js-ES6实现的常用100多个javaScript简短函数封装合集(持续更新中)
Util.js (持续更新中...) 项目地址: https://github.com/dragonir/Util.js 项目描述 Util.js 是对常用函数的封装,方便在实际项目中使用,主要内容包 ...
- phpredis Redis阵列 Redis Arrays
官方URL:https://github.com/phpredis/phpredis/blob/master/arrays.markdown#readme 2017年10月29日20:44:01 Re ...
- Judy Array - Example
“ In computer science and software engineering, a Judy array is a data structure that has high perfo ...
- phpredis -- Redis Arrays用法
Redis Arrays 来自地址:https://github.com/phpredis/phpredis/blob/master/arrays.markdown#readme 扩展原文件array ...
- java中Arrays和Collections等工具类
java.util.Arrays类能方便地操作数组,它提供的所有方法都是静态的.具有以下功能: ² 给数组赋值:通过fill方法. ² 对数组排序:通过sort方法,按升序. ² 比较数组:通过equ ...
- Java Arrays类方法
1:概述 主要谈一谈 Java使用fork/koin类 实现的并发排序 以及对于Stream流的支持的splitetor mismatch() -> 寻找两个数组 第一次出现数据不一致的下 ...
随机推荐
- IOS 绘制基本图形( 画圆、画线、画圆弧、绘制三角形、绘制四边形)
// 当自定义view第一次显示出来的时候就会调用drawRect方法- (void)drawRect:(CGRect)rect { // 1.获取上下文 CGContextRef ctx = UIG ...
- vue组件 $children,$refs,$parent的使用
如果项目很大,组件很多,怎么样才能准确的.快速的寻找到我们想要的组件了?? 1)$refs 首先你的给子组件做标记.demo :<firstchild ref="one"&g ...
- SSH框架快速搭建(Maven)
1.新建Maven项目ssh 2.pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=& ...
- OO第四单元总结
单元架构设计 本单元OO作业主要涉及两个过程,即先根据输入的elements数组建立UML存储模型,而后基于这个模型实现一系列查询判断功能.汲取上单元的经验,建模过程中模型数据容器的选择依据要求实现的 ...
- 关于SQL数据库 msdb.dbo.sp_send_dbmail 函数发送邮件的场景分析
关于SQL数据库 msdb.dbo.sp_send_dbmail 函数发送邮件的场景分析 在推行系统中,时不时会有用户提出希望系统能自动推送邮件,由于手头的工具和能力有限,不少需求都借助于sql se ...
- Uva 长城守卫——1335 - Beijing Guards
二分查找+一定的技巧 #include<iostream> using namespace std; +; int n,r[maxn],Left[maxn],Right[maxn];//因 ...
- 自动化测试 ubuntu多设备连接不识别
环境: ubuntu系统 usb2.0 16个口集线器 遇到问题: 连接手机到第11台设备时出现adb devices不显示的现象导致无法通过adb操作 问题排除思路; 1.通过dmesg查看设备连接 ...
- mysql 报错 Operand should contain 1 column(s)
报错 Operand should contain 1 column(s) 原因 select 后面加了 () select (x,x,x)
- PHP使用CURL_MULTI实现多线程采集
$connomains = array( "http://www.baidu.com/", "http://www.hao123.com/", "ht ...
- 关于在namanode上编写脚本控制DataNode的...
脚本如下:(我的虚拟机名字分别为:wang201 wang 202 wang 203 wang 204) params=$@ i= ; i <= ; i++)) ; do echo ====== ...