FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Projection/JavaScript/b-disp-opt.js at master · HowProgrammingWorks/Projection · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
HowProgrammingWorks
/
Projection
Public
Notifications
You must be signed in to change notification settings
Fork
10
Star
15
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Projection
/
JavaScript
/
b-disp-opt.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
57 lines (43 loc) · 1.43 KB
Breadcrumbs
Projection
/
JavaScript
/
b-disp-opt.js
Copy path
File metadata and controls
57 lines (43 loc) · 1.43 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict'
;
// Projection
const
id
=
(
x
)
=>
x
;
const
projection
=
(
meta
)
=>
(
src
)
=>
meta
.
reduce
(
(
dest
,
[
name
,
fn
=
id
,
field
=
name
]
)
=>
(
dest
[
name
]
=
fn
(
src
[
field
]
)
,
dest
)
,
{
}
)
;
// Display
const
max
=
(
items
)
=>
Math
.
max
(
...
items
)
;
const
maxProp
=
(
key
)
=>
(
items
)
=>
max
(
items
.
map
(
(
x
)
=>
x
[
key
]
)
)
;
const
maxLength
=
maxProp
(
'length'
)
;
const
col
=
(
name
,
data
)
=>
data
.
map
(
(
obj
)
=>
obj
[
name
]
.
toString
(
)
)
;
const
render
=
(
meta
)
=>
(
src
)
=>
{
const
keys
=
meta
.
map
(
(
[
name
]
)
=>
name
)
;
const
maxWidth
=
keys
.
map
(
(
key
)
=>
maxLength
(
col
(
key
,
src
)
)
)
;
const
dest
=
src
.
map
(
(
obj
)
=>
maxWidth
.
map
(
(
width
,
i
)
=>
obj
[
keys
[
i
]
]
.
toString
(
)
.
padEnd
(
width
+
4
)
)
)
;
return
dest
.
map
(
(
row
)
=>
row
.
join
(
''
)
)
.
join
(
'\n'
)
;
}
;
// Dataset
const
persons
=
[
{
name
:
'Marcus Aurelius'
,
city
:
'Rome'
,
born
:
121
}
,
{
name
:
'Victor Glushkov'
,
city
:
'Rostov on Don'
,
born
:
1923
}
,
{
name
:
'Ibn Arabi'
,
city
:
'Murcia'
,
born
:
1165
}
,
{
name
:
'Mao Zedong'
,
city
:
'Shaoshan'
,
born
:
1893
}
,
{
name
:
'Rene Descartes'
,
city
:
'La Haye en Touraine'
,
born
:
1596
}
,
]
;
// Metadata
const
year
=
(
date
)
=>
date
.
getFullYear
(
)
;
const
diff
=
(
y
)
=>
year
(
new
Date
(
)
)
-
year
(
new
Date
(
y
.
toString
(
)
)
)
;
const
upper
=
(
s
)
=>
s
.
toUpperCase
(
)
;
const
md
=
[
[
'name'
]
,
[
'place'
,
upper
,
'city'
]
,
[
'age'
,
diff
,
'born'
]
,
]
;
// Usage
const
pf
=
projection
(
md
)
;
const
data
=
persons
.
map
(
pf
)
;
const
renderer
=
render
(
md
)
;
const
res
=
renderer
(
data
)
;
console
.
log
(
`\n
${
res
}
\n`
)
;
Back
|
FazBrowse Home
|
New Git URL