xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

js repeatify & no for loop All In One

js repeatify & no for loop All In One

js repeatify

https://www.sitepoint.com/5-typical-javascript-interview-exercises/

padStart

//  二维数组生成器
const arrs = [...``.padStart(10)].map(i => []);
// 

https://leetcode-cn.com/problems/image-smoother/

String.prototype.repeatify = String.prototype.repeatify || function (times = 1) {
  console.log(this)
  // String {"abx"}
  return [...``.padStart(times, ` `)].map((item, i) => item = this).join(``);
};

`abx`.repeatify(3);
// "abxabxabx"

arrow function bug


// ES6 无法改变 this 的指向

String.prototype.repeatify = (times = 1, that = this) => [...``.padStart(times, ` `)].map((item, i) => item = that).join(``);

`abx`.repeatify(3);
// "[object Window][object Window][object Window]"

Uint8Array

TypedArray bug

no for & create Array 100


const arr = new Uint8Array(100).map((item, i) => 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]

https://www.cnblogs.com/xgqfrms/p/8982974.html

[...new Uint8Array(8)].map((item, i) => `grid_${i}`);
// (8) ["grid_0", "grid_1", "grid_2", "grid_3", "grid_4", "grid_5", "grid_6", "grid_7"]

[...new Uint8Array(8)].map((item, i) => ({
  key: i,
  value: `grid_${i}`,
}));
// (8) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]0: {key: 0, value: "grid_0"}1: {key: 1, value: "grid_1"}2: {key: 2, value: "grid_2"}3: {key: 3, value: "grid_3"}4: {key: 4, value: "grid_4"}5: {key: 5, value: "grid_5"}6: {key: 6, value: "grid_6"}7: {key: 7, value: "grid_7"}lastIndex: (...)length: 8__proto__: Array(0)

refs



©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2020-06-02 23:02  xgqfrms  阅读(417)  评论(8编辑  收藏  举报