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 than forEach

map


Array 100 & no for

https://www.quora.com/Given-an-array-with-100-elements-numbers-from-0-to-99-if-I-took-a-random-element-out-then-how-would-you-find-that-which-one-I-took-out-How-would-you-solve-this-if-1-The-array-is-sorted-or-2-The-array-is-not-sorted

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

https://hiluluke.cn/


no for & 100 Array & Uint8Array & Typed Arrays的更多相关文章

  1. Typed Arrays in javascripts

    Typed Arrays(类型数组)这个概念,可能对很多人来说非常陌生,那么它是什么,又有什么用途呢? 之前的问题 Web应用程序变得越来越强大,例如新增了音视频处理.WebSocket等多个功能特性 ...

  2. 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 ...

  3. 5个 JS 解构有趣的用途

    摘要: 玩转ES6解构赋值. 原文:5个 JS 解构有趣的用途 译者:前端小智 1. 交换变量 通常交换两个变量的方法需要一个额外的临时变量,来看看例子: let a = 1; let b = 2; ...

  4. 【前端】Util.js-ES6实现的常用100多个javaScript简短函数封装合集(持续更新中)

    Util.js (持续更新中...) 项目地址: https://github.com/dragonir/Util.js 项目描述 Util.js 是对常用函数的封装,方便在实际项目中使用,主要内容包 ...

  5. phpredis Redis阵列 Redis Arrays

    官方URL:https://github.com/phpredis/phpredis/blob/master/arrays.markdown#readme 2017年10月29日20:44:01 Re ...

  6. Judy Array - Example

    “ In computer science and software engineering, a Judy array is a data structure that has high perfo ...

  7. phpredis -- Redis Arrays用法

    Redis Arrays 来自地址:https://github.com/phpredis/phpredis/blob/master/arrays.markdown#readme 扩展原文件array ...

  8. java中Arrays和Collections等工具类

    java.util.Arrays类能方便地操作数组,它提供的所有方法都是静态的.具有以下功能: ² 给数组赋值:通过fill方法. ² 对数组排序:通过sort方法,按升序. ² 比较数组:通过equ ...

  9. Java Arrays类方法

    1:概述 主要谈一谈 Java使用fork/koin类 实现的并发排序 以及对于Stream流的支持的splitetor mismatch()   ->  寻找两个数组 第一次出现数据不一致的下 ...

随机推荐

  1. Deep Learning 优化方法总结

    Stochastic Gradient Descent (SGD) SGD的参数 在使用随机梯度下降(SGD)的学习方法时,一般来说有以下几个可供调节的参数: Learning Rate 学习率 We ...

  2. EM理解(转)

    EM是我一直想深入学习的算法之一,第一次听说是在NLP课中的HMM那一节,为了解决HMM的参数估计问题,使用了EM算法.在之后的MT中的词对齐中也用到了.在Mitchell的书中也提到EM可以用于贝叶 ...

  3. Incorrect key file for table './xx_db/xx_table.MYI'; try to repair it

    解决办法: 可以先运行 CHECK TABLE 表名 检查下是否存在错误. 然后运行 REPAIR TABLE 表名 进行修复.

  4. Echarts样式

    Echarts设置样式如下 <div id="main" style="width: 250px;height:200px;"></div&g ...

  5. Oracle Undo 和 Redo

    1. REDO(重做信息) Redo log file(重做日志文件),是数据库的事务日志. Oracle维护着两类重做日志文件:在线(online)重做日志文件和归档(archived)重做日志文件 ...

  6. 第十五篇、OC_同一个View实现两个手势响应

    #pragma mark-UIGestureRecognizerDelegate Methods // 只要实现这个方法,就可以实现两个手势同时响应 - (BOOL)gestureRecognizer ...

  7. Linux 系统性能

    Linux:PS命令详解与使用   要对进程进行监测和控制,首先必须要了解当前进程的情况,也就是需要查看当前进程,ps命令就是最基本进程查看命令.使用该命令可以确定有哪些进程正在运行和运行的状态.进程 ...

  8. 43.VUE学习之--组件之使用.sync修饰符与computed计算属性超简单的实现美团购物车原理

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. hive数据的导入导出方式

    导入方式 1.load方式 load data local inpath 'local_path' into table tb_name; 从本地复制了文件到表的路径下 应用场景:大部分的使用,文件几 ...

  10. 动态规划:ZOJ1074-最大和子矩阵 DP(最长子序列的升级版)

    To the Max Time Limit:1 Second     Memory Limit:32768 KB Problem Given a two-dimensional array of po ...