Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3fd28c3

Browse files
authored
Update 1486-XOR-operation-in-an-array.js
Added the Code for 1486-XOR-operation-in-an-array.js
1 parent80aa90f commit3fd28c3

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
*@param {number} n
3+
*@param {number} start
4+
*@return {number}
5+
*/
6+
varxorOperation=function(n,start){
7+
letnums=newArray(n).fill(0);// initialize a nums which is the length of n elements with 0 value of Array using Array() nad fill()
8+
9+
for(leti=0;i<n;i++){// loop through the 0 to n
10+
nums[i]=start+(2*i);// current element of nums is equal to sum of start and twice the i
11+
}
12+
13+
returnnums.reduce((a,b)=>a^b);// return the bitwise XOR of all elements of nums using reduce()
14+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp