js & bitwise operator
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的更多相关文章
- js bitwise operation all in one
js bitwise operation all in one 位运算 & 按位与 | 按位或 ^ 按位异或 / XOR let a = 5; // 000000000000000000000 ...
- C# to IL 5 Operator Overloading(操作符重载)
Every operator overload that we use in C#, gets converted to a function call in IL. Theoverloaded &g ...
- HDL之Bitwise operation
1 Verilog 1.1 Bitwise operator Bitwise operators perform a bit wise operation on two operands. They ...
- Javascript模块化简史
Script标签和闭包 RequireJS, AngularJS以及依赖注入 Node.js以及CommonJS的出现 ES6, import, Babel和Webpack https://ponyf ...
- 为什么不要在 JavaScript 中使用位操作符?
如果你的第一门编程语言不是 JavaScript,而是 C++ 或 Java,那么一开始你大概会看不惯 JavaScript 的数字类型.在 JavaScript 中的数字类型是不区分什么 Int,F ...
- vscode主题开发
vscode主题开发教程 https://blog.csdn.net/Suwanqing_su/article/details/105945290 个人配置结果 主题代码 到Vscode放插件的目录中 ...
- SQL 归来
1. PL/SQL 转义 select order#, ……… from **** select col1 from A where col2 like '%\_keywors%' escape ' ...
- pinpoint 安装部署
.markdown-preview:not([data-use-github-style]) { padding: 2em; font-size: 1.2em; color: rgb(171, 178 ...
- atom编辑markdown之上传图片
01atom编辑markdown之上传图片 :first-child { margin-top: 0px; } .markdown-preview:not([data-use-github-style ...
随机推荐
- MongoTemplate聚合(一)$lookup
mongodb 最近入职了新的公司,新公司统一使用的mongodb,es等非关系型数据库.以前对es有一些了解,其实就是灵活的文档类型结构,不受限于关系型数据库的那种字段唯一确定的"死板 ...
- vagrant虚拟化之多网卡网络配置
vagrant虚拟化之多网卡网络配置 一.network改为public 二.查看本地主机网络的ip地址范围(最佳解决方案) 三.vagrant优秀博文 vagrant虚拟化之多网卡网络配置,通过am ...
- redis学习教程五《管道、分区》
redis学习教程五<管道.分区> 一:管道 Redis是一个TCP服务器,支持请求/响应协议. 在Redis中,请求通过以下步骤完成: 客户端向服务器发送查询,并从套接字读取,通常以阻 ...
- Golang内建库学习笔记(1)-sort和container
sort库 利用sort.Sort进行排序须实现如下接口 type Interface interface { // 获取数据集合元素个数 Len() int // 如果i索引的数据小于j所以的数据, ...
- jQuery操作CheckBox的方法(选中,取消,取值)详解
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD ...
- 第2层交换和生成树协议(STP)__第2层的3种交换功能
地址学习(Address Learning):第2层交换机和网桥能够记住在一个接口上所收到的每个帧的源设备硬件地址,而且它们会将这个硬件地址信息输入到被称为转发/过滤表的MAC数据库中. 转发/过滤决 ...
- 关闭Linux - centos7的防火墙
关闭Centos7的防火墙 在每台虚拟机上分别执行以下指令: systemctl stop firewalld.service #停止firewall systemctl disable firewa ...
- 【uva 11491】Erasing and Winning(算法效率--贪心+单调队列)
题意:有一个N位整数,要求输出删除其中D个数字之后的最大整数. 解法:贪心.(P.S.要小心,我WA了2次...)由于规定了整数的位数,那么我们要尽量让高位的数字大一些,也就是要尽量删去前面小的数字. ...
- poj2443Set Operation (bitset)
Description You are given N sets, the i-th set (represent by S(i)) have C(i) element (Here "set ...
- Educational Codeforces Round 89 (Rated for Div. 2) D. Two Divisors (数学)
题意:有\(n\)组数,对于每组数,问是否能找到两个因子\(d_{1},d{2}\),使得\(gcd(d_{1}+d_{2},a_{i}=1)\),如果有,输出它们,否则输出\(-1\). 题解:对于 ...