MCPcopy Create free account
hub / github.com/careercup/CtCI-6th-Edition-JavaScript / drawLine

Function drawLine

chapter05/5.8 - Draw Line/drawLine.js:1–20  ·  view source on GitHub ↗
(screen, width, x1, x2, y)

Source from the content-addressed store, hash-verified

1var drawLine = function(screen, width, x1, x2, y) {
2 var byte;
3 var pixel;
4
5 var findByte = function(x, y, width) {
6 var start = y * width / 8;
7 return start + Math.floor(x / 8);
8 };
9
10 var findPixel = function(x) {
11 return x % 8;
12 };
13
14 for (var i = x1; i <= x2; i++) {
15 byte = findByte(i, y, width);
16 pixel = findPixel(i);
17 screen[byte][pixel] = 1;
18 }
19 return screen;
20};
21
22/* Test */
23

Callers 1

drawLine.jsFile · 0.85

Calls 2

findByteFunction · 0.85
findPixelFunction · 0.85

Tested by

no test coverage detected