33const fs = require ( 'fs' ) ;
44
55/* fp */
6- const pipe = ( ...fns ) => x => fns . reduce ( ( v , f ) => f ( v ) , x ) ;
7- const curry = fn => ( ...args ) => fn . bind ( null , ...args ) ;
6+ const pipe = ( ...fns ) => ( x ) => fns . reduce ( ( v , f ) => f ( v ) , x ) ;
7+ const curry = ( fn ) => ( ...args ) => fn . bind ( null , ...args ) ;
88const map = curry ( ( fn , arr ) => arr . map ( fn ) ) ;
99const join = curry ( ( str , arr ) => arr . join ( str ) ) ;
1010const split = curry ( ( splitOn , str ) => str . split ( splitOn ) ) ;
1111const sort = curry ( ( compareFn , arr ) => arr . sort ( compareFn ) ) ;
1212const filter = curry ( ( filterFn , arr ) => arr . filter ( filterFn ) ) ;
1313
1414/* utility */
15- const first = arr => arr [ 0 ] ;
16- const skipFirst = arr => arr . slice ( 1 ) ;
17- const hasValue = val => ! ! val ;
18- const toStr = val => val . toString ( ) ;
15+ const first = ( arr ) => arr [ 0 ] ;
16+ const skipFirst = ( arr ) => arr . slice ( 1 ) ;
17+ const hasValue = ( val ) => ! ! val ;
18+ const toStr = ( val ) => val . toString ( ) ;
1919const appendCell = ( row , value ) => row . concat ( value ) ;
2020const cellPad = ( index , str , width ) => (
2121 index ? str . padStart ( width ) : str . padEnd ( width )
2222) ;
23- const cellWidth = index => [ 18 , 10 , 8 , 8 , 18 , 6 ] [ index ] ;
23+ const cellWidth = ( index ) => [ 18 , 10 , 8 , 8 , 18 , 6 ] [ index ] ;
2424
2525const renderCell = ( cell , index ) => (
2626 cellPad ( index , toStr ( cell ) , cellWidth ( index ) )
2727) ;
2828const renderRow = pipe ( map ( renderCell ) , join ( '' ) ) ;
2929const renderTable = pipe ( map ( renderRow ) , join ( '\n' ) ) ;
3030
31- const getDensityCell = row => parseInt ( row [ 3 ] , 10 ) ;
31+ const getDensityCell = ( row ) => parseInt ( row [ 3 ] , 10 ) ;
3232const proportion = ( max , val ) => Math . round ( parseInt ( val , 10 ) * 100 / max ) ;
3333const sortRowsByDensity = sort (
3434 ( row1 , row2 ) => getDensityCell ( row2 ) - getDensityCell ( row1 )
@@ -40,16 +40,16 @@ const calcMaxDensity = pipe(
4040 getDensityCell
4141) ;
4242
43- const calcRowsProportionToMax = rows => max => rows . map ( pipe (
43+ const calcRowsProportionToMax = ( rows ) => ( max ) => rows . map ( pipe (
4444 getDensityCell ,
45- densityCell => proportion ( max , densityCell )
45+ ( densityCell ) => proportion ( max , densityCell )
4646) ) ;
4747
48- const appendProportionCell = rows => proportions => rows . map (
48+ const appendProportionCell = ( rows ) => ( proportions ) => rows . map (
4949 ( row , index ) => appendCell ( row , proportions [ index ] )
5050) ;
5151
52- const appendTableProportionCol = rows => pipe (
52+ const appendTableProportionCol = ( rows ) => pipe (
5353 calcMaxDensity ,
5454 calcRowsProportionToMax ( rows ) ,
5555 appendProportionCell ( rows )
@@ -63,7 +63,7 @@ const toLines = pipe(
6363 filter ( hasValue )
6464) ;
6565
66- const readFile = file => fs . readFileSync ( file , 'utf8' ) ;
66+ const readFile = ( file ) => fs . readFileSync ( file , 'utf8' ) ;
6767
6868const getDataset = pipe (
6969 readFile ,
0 commit comments