File tree 1 file changed +42
-0
lines changed
1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ const fs = require ( 'fs' )
2
+ // Complete the reverseArray function below.
3
+ function reverseV1 ( a ) {
4
+ let reversed = [ ]
5
+ for ( let i = a . length - 1 ; i > - 1 ; i -- ) {
6
+ reversed . push ( a [ i ] )
7
+ }
8
+ return reversed
9
+ }
10
+
11
+ const reverseArray = ( a ) => {
12
+ let array_middle_point = Math . round ( ( a . length - 1 ) / 2 )
13
+
14
+ for ( let i = 0 ; i < array_middle_point ; i ++ ) {
15
+ let f_index = a [ i ]
16
+ let l_index = a [ a . length - 1 - i ]
17
+ a [ i ] = l_index
18
+ a [ a . length - 1 - i ] = f_index
19
+ }
20
+ return a
21
+ }
22
+
23
+
24
+
25
+ // const file_gen = () => {
26
+ // for (let i = 0; i < 1000; i++) {
27
+ // fs.appendFileSync('array_file.txt', i)
28
+ // }
29
+ // }
30
+
31
+ const file_gen = ( ) => {
32
+ let arr = [ ]
33
+ for ( let i = 0 ; i < 1000 ; i ++ ) {
34
+ arr . push ( i )
35
+ }
36
+ return arr
37
+ }
38
+
39
+ console . log ( reverseArray ( file_gen ( ) ) )
40
+
41
+
42
+
You can’t perform that action at this time.
0 commit comments