From c2a9dd1f96a79cbfc5be68059fd8a9bd7fcd2b0d Mon Sep 17 00:00:00 2001 From: Kevin Christy Parinussa Date: Mon, 30 May 2022 13:35:59 +0700 Subject: [PATCH] Tugas Quiz Day 3 --- .vscode/launch.json | 17 +++++++++++++++++ FindYear.js | 13 +++++++++++++ MaxNumber.js | 8 ++++++++ SliceEmp.js | 15 +++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 FindYear.js create mode 100644 MaxNumber.js create mode 100644 SliceEmp.js diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..eab977d --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "pwa-node", + "request": "launch", + "name": "Launch Program", + "skipFiles": [ + "/**" + ], + "program": "${file}" + } + ] +} \ No newline at end of file diff --git a/FindYear.js b/FindYear.js new file mode 100644 index 0000000..dc80e68 --- /dev/null +++ b/FindYear.js @@ -0,0 +1,13 @@ +// Remember, the Date constructor takes a zero-based month number, so a +// month value of 10 corresponds to the eleventh month, November +const dates = [new Date(2021, 10, 20), new Date(2020, 3, 12), + new Date(2020, 5, 23), new Date(2022, 3, 18)]; + // Find the first date in 2020 + /* const matchingDate = dates.find(date => date.getFullYear() === 2020); + console.log(matchingDate); */ + + function matchingDate (dates, year){ + return dates.find(date => date.getFullYear() === year); + } + + console.log(matchingDate(dates,2020));//Sun Apr 12 2020 00:00:00 GMT+0700 (Western Indonesia Time) \ No newline at end of file diff --git a/MaxNumber.js b/MaxNumber.js new file mode 100644 index 0000000..b4b5001 --- /dev/null +++ b/MaxNumber.js @@ -0,0 +1,8 @@ +const numbers = [44,131,335,223,21,66,87]; +// This syntax is not allowed. The result is NaN. + +function maxNumber(arrays){ + return Math.max(...numbers) +} + +console.log(maxNumber(numbers)); \ No newline at end of file diff --git a/SliceEmp.js b/SliceEmp.js new file mode 100644 index 0000000..cdf3077 --- /dev/null +++ b/SliceEmp.js @@ -0,0 +1,15 @@ +// terdapat array employees +const cities = ["merak", "tangerang", "jakarta", "bogor", "cianjur", "cimahi", "bandung"]; + +const bogor = cities.indexOf("bogor") + +const citiesSliced = [...cities.slice(0, bogor), ...cities.slice(bogor + 1)] + +function citiesSlice(arrays, cityBetween) { + const jakarta=arrays.indexOf(cityBetween); + const citiesSliced2 = [...arrays.slice(0, jakarta), ...arrays.slice(jakarta + 1)] + return citiesSliced2; +} + +console.log(citiesSlice(cities,"jakarta")); +//['merak', 'tangerang', 'bogor', 'cianjur', 'cimahi', 'bandung'] \ No newline at end of file