From f8ab267af36aa6bf4e8b85bb13129f9d57470375 Mon Sep 17 00:00:00 2001 From: ThanhThao44 Date: Sat, 14 Mar 2020 03:55:37 +0000 Subject: [PATCH 1/3] example 1 --- example.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/example.js b/example.js index 4a78c75..f9ab572 100755 --- a/example.js +++ b/example.js @@ -2,4 +2,17 @@ 'use strict'; -// このファイルを修正して、プルリクエストしてください。 \ No newline at end of file +// このファイルを修正して、プルリクエストしてください。 +var arr = []; +var n = 0; +for (const arg of process.argv.slice(2)) { + arr[n] = arg; + n++; +} +for (var i = (n-1); i>=0; i--){ + console.log((i+1) + "番目は" + arr[i] + "です"); + if(i===0){ + break; + } + console.log(); +} \ No newline at end of file From 102e90d79fdc02b8d4715546df0df8e007a36689 Mon Sep 17 00:00:00 2001 From: ThanhThao44 Date: Mon, 23 Mar 2020 04:43:29 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=E8=AA=B2=E9=A1=8C6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example.js | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/example.js b/example.js index f9ab572..24b19e0 100755 --- a/example.js +++ b/example.js @@ -5,14 +5,28 @@ // このファイルを修正して、プルリクエストしてください。 var arr = []; var n = 0; + +function sum(arr){ + var sum = 0; + for (var i = 0; i < arr.length; i++){ + sum += arr[i]; + } + return sum; +} + for (const arg of process.argv.slice(2)) { - arr[n] = arg; - n++; + arr[n] = Number(arg); + n++; } -for (var i = (n-1); i>=0; i--){ - console.log((i+1) + "番目は" + arr[i] + "です"); - if(i===0){ - break; - } - console.log(); -} \ No newline at end of file + +var s = sum(arr); +var a = (s%n)/n; + +if(a > 0.5){ + console.log(Math.floor(s/n) + 1); +} +else{ + console.log(Math.floor(s/n)); +} + + From dba31a1d369a841008baec4cf15b77d5bca474b5 Mon Sep 17 00:00:00 2001 From: ThanhThao44 Date: Fri, 27 Mar 2020 11:21:31 +0000 Subject: [PATCH 3/3] fix --- example.js | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/example.js b/example.js index 24b19e0..3ffe63c 100755 --- a/example.js +++ b/example.js @@ -6,27 +6,12 @@ var arr = []; var n = 0; -function sum(arr){ - var sum = 0; - for (var i = 0; i < arr.length; i++){ - sum += arr[i]; - } - return sum; -} - for (const arg of process.argv.slice(2)) { arr[n] = Number(arg); n++; } +arr.sort(function(a,b){return a-b}); -var s = sum(arr); -var a = (s%n)/n; - -if(a > 0.5){ - console.log(Math.floor(s/n) + 1); -} -else{ - console.log(Math.floor(s/n)); -} +console.log(Math.floor((arr[0]+arr[n-1])/2));