-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1ce6648
Showing
10 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |