Last active
December 4, 2019 02:36
-
-
Save absyah/6ed2a652e5429b21f31915fced97505c to your computer and use it in GitHub Desktop.
Whiteboard Coding Test
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
cari kata “forstok” dari sebuah kata: | |
contoh | |
-ffffforrrrrrstookkkk answer YES | |
-forastok answer YES | |
-forlikesvrtyeok answer YES | |
-dhkortfsuhuahjdhsjhdjshs answer NO | |
function forstokString(s) { | |
var str = “forstok”; | |
if (s.length < str.length) { | |
return "NO"; | |
} | |
var j = 0; | |
for (var i = 0; i < s.length; i++) { | |
if (j < str.length && s.charAt(i) == str.charAt(j)) { | |
j++; | |
} | |
} | |
return (j == str.length ? "YES" : "NO"); | |
} |
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
const x = 110; | |
var nilai = x; | |
var balik = 0; | |
while(nilai >0){ | |
balik = (nilai % 10) + (balik * 10); | |
nilai = Math.floor(nilai / 10); | |
} | |
console.log(balik); | |
if(x == balik){ | |
console.log("palindrome"); | |
}else{ | |
console.log("bukan palindrome"); | |
} |
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
variable a = a , b = b, coba buat function swap menjadi a = 10 dan b = 2. tidak boleh ada variable tambahan & string | |
var a = 10; | |
var b = 2; | |
a = a+b; | |
b = a-b; | |
a = a-b; | |
console.log(a); | |
console.log(b); |
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
class Stack { | |
constructor() | |
{ | |
this.items = []; | |
} | |
getItems(){ | |
return this.items; | |
} | |
push(element) | |
{ | |
this.items.push(element); | |
} | |
pop() | |
{ | |
if (this.items.length == 0) | |
return "Underflow"; | |
return this.items.pop(); | |
} | |
peek() | |
{ | |
return this.items[this.items.length - 1]; | |
} | |
isEmpty() | |
{ | |
return this.items.length == 0; | |
} | |
printStack() | |
{ | |
return this.items; | |
} | |
} |
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
# console logs the numbers from 1 to n, where n is the integer the function takes as its parameter | |
# logs fizz instead of the number for multiples of 3 | |
# logs buzz instead of the number for multiples of 5 | |
# logs fizzbuzz for numbers that are multiples of both 3 and 5 | |
const fizzBuzz = num => { | |
for(let i = 1; i <= num; i++) { | |
// check if the number is a multiple of 3 and 5 | |
if(i % 3 === 0 && i % 5 === 0) { | |
console.log('fizzbuzz') | |
} // check if the number is a multiple of 3 | |
else if(i % 3 === 0) { | |
console.log('fizz') | |
} // check if the number is a multiple of 5 | |
else if(i % 5 === 0) { | |
console.log('buzz') | |
} else { | |
console.log(i) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment