js & bitwise operator

bitwise operator

https://github.com/Advanced-Frontend/Daily-Interview-Question/issues/161#issuecomment-521172471

https://github.com/xgqfrms/learn-javascript-with-mdn/issues/8

demo


"use strict"; /**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2019-08-14
*
* @description auto-sevent-times-without-math.js
* @description 不用加减乘除运算符, 求整数的7倍
* @description js array get sum value without call math methods
* @augments
* @example eval([1,2,3].join('+'));// 6
* @link https://stackoverflow.com/questions/1230233/how-to-find-the-sum-of-an-array-of-numbers
*
*/ let log = console.log; const autoSevenTimes = (int = 0, times = 7, debug = false) => {
let result = [];
if (!int) {
return 0;
} else {
for (let i = 0; i < times; i++) {
result.push(int);
}
}
// result = result.reduce((acc, item) => acc + item);
result = eval(result.join(`+`));
if(debug) {
log(`result = `, result);
}
return result;
}; let num = 3;
autoSevenTimes(num);
// expect: 3 * 7 = 21

bitwise operator

https://repl.it/@xgqfrms/bitwise-operator-and-left-shift-and-right-shift

const autoSeventTimes = (num = 0, times = 7) => {
let x = Math.floor(times / 2);
return (num << x) - num;
}; let xyz = autoSeventTimes(3);
// 21 console.log(`xyz =`, xyz);

typed array

I think using typed array is more meaningful.


let result = [].concat(...([...new Uint8Array(num).map(item => item = 1)].map(x => [...new Uint8Array(7).map(item => item = 1)]))); console.log(result, result.length);


xgqfrms 2012-2020

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


js & bitwise operator的更多相关文章

  1. js bitwise operation all in one

    js bitwise operation all in one 位运算 & 按位与 | 按位或 ^ 按位异或 / XOR let a = 5; // 000000000000000000000 ...

  2. C# to IL 5 Operator Overloading(操作符重载)

    Every operator overload that we use in C#, gets converted to a function call in IL. Theoverloaded &g ...

  3. HDL之Bitwise operation

    1 Verilog 1.1 Bitwise operator Bitwise operators perform a bit wise operation on two operands. They ...

  4. Javascript模块化简史

    Script标签和闭包 RequireJS, AngularJS以及依赖注入 Node.js以及CommonJS的出现 ES6, import, Babel和Webpack https://ponyf ...

  5. 为什么不要在 JavaScript 中使用位操作符?

    如果你的第一门编程语言不是 JavaScript,而是 C++ 或 Java,那么一开始你大概会看不惯 JavaScript 的数字类型.在 JavaScript 中的数字类型是不区分什么 Int,F ...

  6. vscode主题开发

    vscode主题开发教程 https://blog.csdn.net/Suwanqing_su/article/details/105945290 个人配置结果 主题代码 到Vscode放插件的目录中 ...

  7. SQL 归来

    1. PL/SQL 转义 select order#, ………  from **** select col1 from A where col2 like '%\_keywors%' escape ' ...

  8. pinpoint 安装部署

    .markdown-preview:not([data-use-github-style]) { padding: 2em; font-size: 1.2em; color: rgb(171, 178 ...

  9. atom编辑markdown之上传图片

    01atom编辑markdown之上传图片 :first-child { margin-top: 0px; } .markdown-preview:not([data-use-github-style ...

随机推荐

  1. oracle创建表并加索引

    一个语句创建Oracle所有表的序列 -- 动态创建序列 2 declare 3 cursor c_job is 4 select TABLE_NAME from user_tables; 5 6 c ...

  2. compare-algorithms-for-heapqsmallest

    Compare algorithms for heapq.smallest « Python recipes « ActiveState Code http://code.activestate.co ...

  3. 应答流式RPC 请求流式RPC 向流式RPC 流式RPC的三种具体形式

    https://mp.weixin.qq.com/s/pWwSfXl71GQZ3KPmAHE_dA 用Python进行gRPC接口测试(二) 大帆船 搜狗测试 2020-02-07   上期回顾:用P ...

  4. http 和 https 有何区别?如何灵活使用?

    http是HTTP协议运行在TCP之上.所有传输的内容都是明文,客户端和服务器端都无法验证对方的身份. https是HTTP运行在SSL/TLS之上,SSL/TLS运行在TCP之上.所有传输的内容都经 ...

  5. Java三种IO模型和LinuxIO五种IO模型

    Java: https://github.com/Snailclimb/JavaGuide/blob/master/docs/java/BIO-NIO-AIO.md https://github.co ...

  6. postfix “ Sender address rejected: not logged in”

      一.问题 先说一下问题,我们公司有两台邮件服务器,分别是不同的域名但是用的是同一个用户认证,最近老有人反应说,有匿名邮件就是通过类似这种网站,进行使用你们公司的SMTP邮件服务器进行发送垃圾邮件 ...

  7. python——模块、标准库、第三方模块安装

    模块(module)简介 模块化--指将一个完整的程序分解为一个一个小的模块,通过将模块组合,来搭建出一个完整的程序. 模块化的特点: ① 方便开发 ② 方便维护 ③ 模块可以复用! 在Python中 ...

  8. (30)Linux文本处理

    1.cat命令:连接文件并打印输出到标准输出设备 cat 命令可以用来显示文本文件的内容(类似于 DOS 下的 type 命令),也可以把几个文件内容附加到另一个文件中,即连接合并文件. cat 命令 ...

  9. ACM 模板库

    Template For ACM 一. 字符串 标准库 sscanf sscanf(const char *__source, const char *__format, ...) :从字符串 __s ...

  10. Codeforces Round #626 Div2 D. Present(位掩码,二分)

    题目链接:https://codeforces.com/contest/1323/problem/D 题意:给了大小为4e5的数组a,其中1<=ai<=1e7.求所有点对和的异或和,即: ...