Lodash _.bitwiseXor() 方法
Lodash _.bitwiseXor() 方法返回对所有给定参数使用按位异或 (^)运算符的结果。
句法:
_.bitwiseXor(val1, val2, ..., valn);
参数:此方法取 n 个值并对其进行按位异或运算。
返回值:此方法返回对所有参数使用按位异或运算符(^) 的结果。
注意:这在普通 JavaScript 中不起作用,因为它需要安装 lodash.js contrib 库。 Lodash.js contrib 库可以使用npm install lodash-contrib –save 安装。
示例 1:
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
var bX = _.bitwiseXor( 1, 2, 3, 4 );
console.log("The bitwiseXor is :", bX);
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
var bX = _.bitwiseXor( 0, 8 );
console.log("The bitwiseXor is :", bX);
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
var bX = _.bitwiseXor( 1 );
console.log("The bitwiseXor is :", bX);
输出:
The bitwiseXor is : 4
示例 2:
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
var bX = _.bitwiseXor( 0, 8 );
console.log("The bitwiseXor is :", bX);
输出:
The bitwiseXor is : 8
示例 3:
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
var bX = _.bitwiseXor( 1 );
console.log("The bitwiseXor is :", bX);
输出:
The bitwiseXor is : 1