Skip to content

Commit

Permalink
Tugas Quiz Day 2
Browse files Browse the repository at this point in the history
  • Loading branch information
kaysypy committed May 30, 2022
0 parents commit 1ce6648
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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": [
"<node_internals>/**"
],
"program": "${file}"
}
]
}
19 changes: 19 additions & 0 deletions HowManyElapsedTime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/** berapa banyak tahun kabisat antara tahun1 ke tahun2 */

function howManyKabisat(year1,year2){
while(year1<year2){
if(isKabisat(year1)){
console.log(year1);
}
year1++;
}
}

function isKabisat(year){
let checkLeap=year;
if(checkLeap%4==0 ){
console.log(checkLeap);
}
}

console.log(howManyKabisat(1997,2021));
21 changes: 21 additions & 0 deletions Permutation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const checkPermute = function(stringOne, stringTwo) {
// if different lengths, return false
if(stringOne.split("").length!=stringTwo.split("").length){
return false;
}
// else sort and compare
// (doesnt matter how it's sorted, as long as it's sorted the same way)
else{
if(stringOne.split("").sort().join()!=stringTwo.split("").sort().join()){
return false;
}
else{
return true;
}
}
};

console.log(checkPermute('aba', 'aab'))//true;
console.log(checkPermute('aba', 'aaba'))//false;
console.log(checkPermute('aba', 'aa'))//false;

35 changes: 35 additions & 0 deletions PrimeNumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

function showPrimeNumber(n){
isPrime(n);
}

function isPrime(n){
for (let i = 2; i <= n; i++) {
let flag = 0;

// looping through 2 to user input number
for (let j = 2; j < i; j++) {
if (i % j == 0) {
flag = 1;
break;
}
}

// if number greater than 1 and not divisible by other numbers
if (i > 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
*/

31 changes: 31 additions & 0 deletions Segitiga.js
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions StringToDate.js
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions isArrayEqual.js
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions isCharsUnique.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function isCharsUnique(string){
for(let i=0;i<string.length;i++){
for(let j=1+i;j<string.length;j++){
if(string[i]==string[j]){
return false;
}
}
}
return true;
}

console.log(isCharsUnique('abcdefg'));//true
console.log(isCharsUnique('abcdefga'));//false
15 changes: 15 additions & 0 deletions maxlength.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function maxWordLength(params) {
let maxArr=params.split(" ");
let numArr=[];

for(let i=0;i<maxArr.length;i++){
numArr.push(maxArr[i].length);
}

const max = Math.max(...numArr);
const indexMax=numArr.indexOf(max);
return maxArr[indexMax];
}

console.log(maxWordLength("aku suka bootcamp sentul city"));//bootcamp

11 changes: 11 additions & 0 deletions palindrome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function isPalindrome(word){
let wordArr=word.split("");
let reverseWord=wordArr.reverse().join();
for(let i=0;i<=wordArr.length;i++){
if(wordArr[i]==reverseWord[i]){
return true;
}
}
}

console.log(isPalindrome('kasur ini rUsak'));//true

0 comments on commit 1ce6648

Please sign in to comment.