Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 71 additions & 3 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,91 @@
function min(arr) {
//1. sort ascending => get first item

// var i = arr.sort()
// return i.slice(0, 1)

// arr.sort(function (a, b) {
// return a - b
// })
// return arr[0]

//2. Math.min
return Math.min(...arr)

//3. Array.reduce
// return arr.reduce(function (a, b) {
// return (a < b ? a : b)
// })
}

function max(arr) {
//1. sort
// arr.sort(function (a, b) {
// return b - a
// })
// return arr[0]


//2. Math.max
return Math.max(...arr)

//3. reduce
// return arr.reduce(function (a, b) {
// return (a > b ? a : b)
// })

}

function mean(arr) {

var jumlah = 0
for (var i = 0; i < arr.length; i++) {
jumlah += arr[i]
}
return Math.round(jumlah / arr.length)
//Math.round berfungsi untuk membulatkan decimal
//function returns the value of a number rounded to the nearest integer.
}

function odds(arr) {

var result = []
for (var i = 0; i < arr.length; i++) {
if (arr[i] % 2 === 1) {
result.push(arr[i])
}
}
return result.join('-')
}

function evens(arr) {
// var odd = arr.filter(function getodd(m) {
// return m % 2 === 1
// })
// .join('-')
// return odd
// }

// var odd = arr.filter(function getodd(m) {
// return m % 2 === 1
// })
// return odd.join('-')
// }


function evens(arr) {
var result = []
for (var i = 0; i < arr.length; i++) {
if (arr[i] % 2 === 0) {
result.push(arr[i])
}
}
return result.join('-')
}

// var even = arr.filter(function getevens(n) {
// return n % 2 === 0
// })
// return even.join('-')
// }

function numberProcessing(arr) {
return 'Min: ' + min(arr) + ', Max: ' + max(arr) + ', Mean: ' + mean(arr) + ', Odds: ' + odds(arr) + ', Evens: ' + evens(arr)
}
Expand Down