From 1ce6648eea005987f918c2ba4f9cca0e04e75a51 Mon Sep 17 00:00:00 2001 From: Kevin Christy Parinussa Date: Mon, 30 May 2022 10:39:27 +0700 Subject: [PATCH] Tugas Quiz Day 2 --- .vscode/launch.json | 17 +++++++++++++++++ HowManyElapsedTime.js | 19 +++++++++++++++++++ Permutation.js | 21 +++++++++++++++++++++ PrimeNumber.js | 35 +++++++++++++++++++++++++++++++++++ Segitiga.js | 31 +++++++++++++++++++++++++++++++ StringToDate.js | 15 +++++++++++++++ isArrayEqual.js | 14 ++++++++++++++ isCharsUnique.js | 13 +++++++++++++ maxlength.js | 15 +++++++++++++++ palindrome.js | 11 +++++++++++ 10 files changed, 191 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 HowManyElapsedTime.js create mode 100644 Permutation.js create mode 100644 PrimeNumber.js create mode 100644 Segitiga.js create mode 100644 StringToDate.js create mode 100644 isArrayEqual.js create mode 100644 isCharsUnique.js create mode 100644 maxlength.js create mode 100644 palindrome.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/HowManyElapsedTime.js b/HowManyElapsedTime.js new file mode 100644 index 0000000..65ec661 --- /dev/null +++ b/HowManyElapsedTime.js @@ -0,0 +1,19 @@ +/** berapa banyak tahun kabisat antara tahun1 ke tahun2 */ + +function howManyKabisat(year1,year2){ + while(year1 1 && flag == 0) { + console.log(i); + } + } +} + +console.log(showPrimeNumber(100)); +/** + +2 3 5 7 11 +13 17 19 23 29 +31 37 41 43 47 +53 59 61 67 71 +73 79 83 89 97 + + */ + diff --git a/Segitiga.js b/Segitiga.js new file mode 100644 index 0000000..27e6585 --- /dev/null +++ b/Segitiga.js @@ -0,0 +1,31 @@ +/** buat segitiga */ +let triangle1=''; +for (let i = 1; i < 5; i++) { + for (let j = 1; j < 6-i; j++) { + triangle1+=j+" "; + } + console.log(triangle1+"\n"); + triangle1=''; +} +// output +// 1 2 3 4 +// 1 2 3 +// 1 2 +// 1 + + +let triangle2=''; +for (let i = 0; i < 6; i++) { + for (let j = 5-i; j > 0; j--) { + triangle2+=j+" "; + } + console.log(triangle2+"\n"); + triangle2=''; +} + +// output +// 5 4 3 2 1 +// 4 3 2 1 +// 3 2 1 +// 2 1 +// 1 diff --git a/StringToDate.js b/StringToDate.js new file mode 100644 index 0000000..6d92a1d --- /dev/null +++ b/StringToDate.js @@ -0,0 +1,15 @@ +/** ubah value string ke date + * gunakan split + * inputan s = bulan/hari/tahun +*/ +function strToDate(s){ + for(let i=0;i<3;i++){ + if(isNaN(s.split("/")[i])){ + return s+" bad format date"; + } + } + return new Date(s); +} + +console.log(strToDate('12/30/2021'));//Thu Dec 30 2021 00:00:00 GMT+0700 (Western Indonesia Time) +console.log(strToDate('12/aa/bb')); //12/aa/bb bad format date diff --git a/isArrayEqual.js b/isArrayEqual.js new file mode 100644 index 0000000..3e88281 --- /dev/null +++ b/isArrayEqual.js @@ -0,0 +1,14 @@ +function isArraysEqual(arrayA, arrayB) { + for(let i=0;i<4;i++){ + if(arrayA[i]!=arrayB[i]){ + return false; + } + } + return true; +} + +const fruitNamesA = ['rambutan', 'durian', 'jeruk', 'nangka']; +const fruitNamesB = ['rambutan', 'durian', 'jeruk', 'nangka']; +const fruitNamesC = ['anggur', 'apel', 'mangga', 'alpukat']; +console.log(isArraysEqual(fruitNamesA, fruitNamesB)); // true +console.log(isArraysEqual(fruitNamesA, fruitNamesC)); // false \ No newline at end of file diff --git a/isCharsUnique.js b/isCharsUnique.js new file mode 100644 index 0000000..f5a3147 --- /dev/null +++ b/isCharsUnique.js @@ -0,0 +1,13 @@ +function isCharsUnique(string){ + for(let i=0;i