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. 利用Python实现 队列的算法

    以下内容都是来自“悟空“大神的讲解,听他的视频课,利用Python实现堆栈的算法,自己做了一些小总结,可能会存在自己理解的一些误区, 1.栈的实现 队列的特征是先进先出,同我们生活中的队列具有相同的特 ...

  2. Exceptions and Errors on iOS

    异常:程序缺陷导致:不可恢复:给开发者使用: 错误:资源受限导致:可恢复:提示给用户. https://blog.jayway.com/2010/10/13/exceptions-and-errors ...

  3. geoNear查询 near查询的升级版

    geoNear查询可以看作是near查询点进化版 geoNear查询使用runCommand命令进行使用,常用使用如下: db.runCommand({ geoNear:<collection& ...

  4. 地理位置索引 2d索引

    地址位置索引:将一些点的位置存储在mongodb中,创建索引后,可以按照位置来查找其他点 子分类: .2d索引:平面地理位置索引,用于存储和查找平面上的点. .2dsphere索引:球面地理位置索引, ...

  5. mongodb索引 全文索引使用限制

    全文索引非常强大,但是同样存在很多限制,我们来看以下去全文索引的使用限制: 1.每次查询,只能指定一个$text查询 2.$text查询不能出现在$nor查询中 之前没有接触过$nor查询,$nor查 ...

  6. MySQL8.0在Windows下的安装和使用

    前言 MySQL在Windows下有2种安装方式:1.图形化界面方式安装MySQL 2.noinstall方式安装MySQL.在这里,本文只介绍第二种方式:以noinstall方式安装MySQL,以及 ...

  7. python_76_json与pickle反序列化2

    import pickle def say(name):#序列化时用完会释放,要想反序列化,要重新写上该函数,否则会出错 print('我的高中:', name)#可以和之前的序列化函数不同 f=op ...

  8. python生成随机数

    import random rnd=rand.uniform(0,10)

  9. 第四篇、Swift_Podfile文件配置格式

    # Uncomment this line to define a global platform for your project platform :ios, '9.0' # Comment th ...

  10. js call 函数

    function bb(){ console.log(this.x)   } function cc(){ this.x = 200 } var p = new cc(); bb.call(p) // ...