File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * Definition for read4()
3
+ *
4
+ * @param {character[] } buf Destination buffer
5
+ * @return {number } The number of actual characters read
6
+ * read4 = function(buf) {
7
+ * ...
8
+ * };
9
+ */
10
+
11
+ /**
12
+ * @param {function } read4()
13
+ * @return {function }
14
+ */
15
+ const solution = function ( read4 ) {
16
+ const internalBuf = [ ]
17
+ /**
18
+ * @param {character[] } buf Destination buffer
19
+ * @param {number } n Number of characters to read
20
+ * @return {number } The number of actual characters read
21
+ */
22
+ return function ( buf , n ) {
23
+ let readChars = 0
24
+ while ( n > 0 ) {
25
+ if ( internalBuf . length === 0 ) {
26
+ if ( read4 ( internalBuf ) === 0 ) {
27
+ return readChars
28
+ }
29
+ }
30
+ buf . push ( internalBuf . shift ( ) )
31
+ readChars ++
32
+ n --
33
+ }
34
+ return readChars
35
+ }
36
+ }
You can’t perform that action at this time.
0 commit comments