Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
Create free account
hub
/
github.com/careercup/CtCI-6th-Edition-JavaScript
/ insertion
Function
insertion
chapter05/5.1 - Insertion/insertion.js:1–6 ·
view source on GitHub ↗
(N, M, i, j)
Source
from the content-addressed store, hash-verified
1
const
insertion = (N, M, i, j) => {
2
const
bitMask = (-1 << (j + 1)) | ((1 << i) - 1);
3
const
clearedN = N & bitMask;
4
const
shiftedM = M << i;
5
return
clearedN | shiftedM;
6
};
7
8
/* TEST */
9
const
N = parseInt(10000000000, 2);
Callers
1
insertion.js
File · 0.85
Calls
no outgoing calls
Tested by
no test coverage detected