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');

foris 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() -> 寻找两个数组 第一次出现数据不一致的下 ...
随机推荐
- signal函数:void (*signal(int,void(*)(int)))(int);
http://blog.chinaunix.net/uid-20178794-id-1972862.html signal函数:void (*signal(int,void(*)(int)))(int ...
- 【51nod1677】treecnt(树上数学题)
点此看题面 大致题意: 给你一个节点从1~n编号的树,让你从中选择k个节点并通过选择的边联通,且要使选择的边数最少,让你计算对于所有选择k个节点的情况最小选择边数的总和. 题解 这道题乍一看很麻烦:最 ...
- iOS 制作表格 (数据源控制行,列数)
记得去年面试的过程中,有一个面试官问我怎么制作表格.由于之前也没有做过,当时有点懵逼,今天想起来了,就用tableview制作了一个,望不要有人像我一样掉坑了, 直接上代码: // // ViewCo ...
- Being a Good Boy in Spring Festival(博弈)
Being a Good Boy in Spring Festival Problem Description一年在外 父母时刻牵挂春节回家 你能做几天好孩子吗寒假里尝试做做下面的事情吧 陪妈妈逛一次 ...
- 标准输入输出 stdio 流缓冲 buffering in standard streams
From : http://www.pixelbeat.org/programming/stdio_buffering/ 译者:李秋豪 我发现找出标准流用的是什么缓冲是一件困难的事. 例如下面这个使用 ...
- python_65_生成器1
# map()函数 # map()是 Python 内置的高阶函数,它接收一个函数 f 和一个 list,并通过把函数 f 依次作用在 list 的每个元素上,得到一个新的 list 并返回. # 例 ...
- Javascript笔记部分
写入HTML输出 document.write(“<h1>”); 改变HTML内容 x = document.getElementById(“demo”) //查找元素 后面可以.valu ...
- 复选框(checkbox)、多选框
1.需求分析 可同时选中多个选项,实现全选.全不选.反选等功能. 2.技术分析 基础的HTML.CSS.JavaScript. 3.详细分析 3.1 HTML部分 图示是一个列表加底部一段文字说明,列 ...
- macOS如何正确驱动集成显卡HDMI(包括视频和音频)
聊聊如何正确驱动集成显卡HDMI(包括视频和音频)必备条件:1.必须使用AppleHDA驱动声卡(仿冒.clover.applealc都可以的),使用voodoo驱动声卡应该不行的.2.dsdt或者s ...
- ubuntu16.04更换镜像源
1.备份原有 cp /etc/apt/sources.list /etc/apt/sources.list.old 2.打开阿里巴巴镜像源: https://opsx.alibaba.com/mir ...