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. 【PC Basic】CPU、核、多线程的那些事儿

    一.CPU与核的概念 1.半导体中名词[Wafer][Chip][Die]中文名字和用途 Wafer--晶圆 wafer 即为图片所示的晶圆,由纯硅(Si)构成.一般分为6英寸.8英寸.12英寸规格不 ...

  2. sentry 错误监控 报警

    错误监控 报警 Sentry | Error Tracking Software - JavaScript, Python, PHP, Ruby, more https://sentry.io/wel ...

  3. poj2185Milking Grid

    Milking Grid Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 8325   Accepted: 3588 Desc ...

  4. JQuery——基本概念

    ###JQuery语法 格式:$(selector).action() 美元符号$本身是JQuery对象的缩写 选择符selector查询和查找HTML元素 Action执行对元素的操作 ###JQu ...

  5. spark SQL (四)数据源 Data Source----Parquet 文件的读取与加载

    spark SQL Parquet 文件的读取与加载 是由许多其他数据处理系统支持的柱状格式.Spark SQL支持阅读和编写自动保留原始数据模式的Parquet文件.在编写Parquet文件时,出于 ...

  6. java 去掉重复的数字

    public static void main(String[] args) { String s="1,2,2,2,2,2,3,3,3"; String[] array = s. ...

  7. zabbix设置告警

    1.配置告警媒介 邮件: 微信: #!/usr/bin/env python # -*- coding: utf-8 -*- import urllib,urllib2,datetime,hashli ...

  8. Redis挖矿原理及防范

    笔者也曾经被挖矿病毒侵袭过,灰常难受,但是其实你只要了解入侵的手段就非常好防范了,今天我们就演示一下如果通过Redis进行提权获取远程服务器的Root用户. 1.首先我们需要一些先决条件 条件一:你首 ...

  9. 用powershell实现,管理github自动化

     用powershell实现,管理github自动化 搜索关键字如下:PowerShellForGitHub powershell 传教士 原创文章.始于 2021-02-04 允许转载,但必须保留名 ...

  10. 使用VisualStudio直接运行简单的C#语句

    场景 经常有这样的需求, 想要测试一些简单的C#语法, 或者测试一下 文件 目录 操作相关的Api, 通常的做法是建立一个C#控制台项目, 然后写代码测试, 但是这样的做法对测试简单的语法和Api来说 ...