删除重复并在Div中显示Unique With Count

时间:2015-06-06 12:39:05

标签: javascript html html5

我想计算" 0""的总数。反对标签" a",并计算" 1"的总数。反对标签" a"。并计算" 1"的总数反对标签" b"。

股利:输入1

[   
    {y: 0 ,  label: 'a'}, 
    {y: 0 ,  label: 'a'}, 
    {y: 1 ,  label: 'a'}, 
    {y: 1 ,  label: 'a'}, 
    {y: 1, label: 'b'}, 
    {y: 1, label: 'b'}, 
    {y: 1, label: 'b'}

]

股利:输入2

[   
    {y: 0 ,  label: 'a'}, 
    {y: 0 ,  label: 'a'}, 
    {y: 1 ,  label: 'a'}, 
    {y: 1 ,  label: 'a'}, 
    {y: 1, label: 'b'}, 
    {y: 1, label: 'b'}, 
    {y: 1, label: 'b'}

]

我想要输出,重复删除" 我希望来自about输入的输出是:

Div输出1:这将只计算" 1"" div input1

[   
        {y: 2,  label: 'a'},
        {y: 3,  label: 'b'}, 

    ]

Div output2:这将只计算" 0'" div input2

[   
        {y: 2,  label: 'a'},
        {y: 0,  label: 'b'}, 

    ]

1 个答案:

答案 0 :(得分:0)

Yup是可能的!

这个问题被称为聚合问题,通常你会使用map和reduce来聚合值

set term wxt
set title "My title "
set polar
set angles degrees

set grid polar 360
set size square
set style data lines
set key top left

unset border

set grid ls 0
set linetype 1 lc rgb 'red' lw 2 pt 7 ps 2

M=2.2
npoints = 7

minima = "0 0 0 0 0 0 0" # adjust and add more as necessary
maxima = "1 1 1 1 1 1 1"

a(n) = 360./npoints*n
amin(n) = 0.0 + word(minima,int(n))
amax(n) = 0.0 + word(maxima,int(n))

do for [i=1:npoints] {
    set arrow i from 0,0 to first M*cos(a(i)), M*sin(a(i))
    set label i sprintf("M%.f",i) at M*cos(a(i)),M*sin(a(i)) \
        center offset char 1,1
}

set object 1 circle at 0,0 size M fillc rgb "yellow" behind
set object 2 circle at 0,0 size 1 fillc rgb "white" behind

set xrange [0:1]
set yrange [0:1]

set xtics axis 0,0.5,M
unset ytics

set rrange [0:M]

set rtics (""0,""0.25,""0.5,""0.75,"{/:Bold Limit}"1,""1.25,""1.50,""1.75,""2)
set rtics scale 0 format ''

set style fill transparent solid 0.5
set style function filledcurves y1=0.5
set grid noxtics nomxtics noytics nomytics front

plot '-' us (a($1)):(($2-amin($1))/(amax($1)-amin($1))) \
        w filledcurve closed lt 1 title "AAA",\
     '-' us (a($1)):(($2-amin($1))/(amax($1)-amin($1))) \
         w filledcurve closed lt 2 title "BBB"

1 2.1
2 1
3 0.1
4 0.5
5 0.5
6 0.1
7 0.5
EOF
1 2.2
2 0.9
3 0.9
4 0.2
5 0.3
6 0.1
7 1.8
EOF