回答編集履歴

2

bichousei

2019/06/20 03:22

投稿

yambejp
yambejp

スコア115012

test CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
  ```javascript
24
24
 
25
- const ranking=(arr,num)=>[1,2].indexOf(num)<0?null:arr.map((x,y,z)=>z.filter(w=>(num==2)?w<x:w>x).length+1).map((x,y,z)=>{const l=z.filter(w=>w==x).length;return l==1?x:((l)*(x*2+l-1)/2/l)});
25
+ const ranking=(arr,num)=>[1,2].indexOf(num)<0?null:arr.map((x,y,z)=>z.filter(w=>(num==2)?w<x:w>x).length+1).map((x,y,z)=>{const l=z.filter(w=>w==x).length;return l==1?x:(x*2+l-1)/2}); // 微調整
26
26
 
27
27
  let a = [56,66,68,77,77,83,56];
28
28
 

1

平均

2019/06/20 03:22

投稿

yambejp
yambejp

スコア115012

test CHANGED
@@ -15,3 +15,19 @@
15
15
  console.log(ranking(a,3)); //null
16
16
 
17
17
  ```
18
+
19
+
20
+
21
+ # 平均
22
+
23
+ ```javascript
24
+
25
+ const ranking=(arr,num)=>[1,2].indexOf(num)<0?null:arr.map((x,y,z)=>z.filter(w=>(num==2)?w<x:w>x).length+1).map((x,y,z)=>{const l=z.filter(w=>w==x).length;return l==1?x:((l)*(x*2+l-1)/2/l)});
26
+
27
+ let a = [56,66,68,77,77,83,56];
28
+
29
+ console.log(ranking(a,1));
30
+
31
+ console.log(ranking(a,2));
32
+
33
+ ```