Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

done all :) #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 53 additions & 7 deletions async/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,34 @@ class RNG {

return result;
}

static gatchaRoll(times, callback) {
let arr = []
for (var i = 0; i < times; i++) {
// console.log(RNG.roll())
arr.push(RNG.roll())
arr.sort(function(a, b) {return b - a})
}
callback(arr[0] || 0)
// console.log(arr[0] || 0);
}

static gatchaRollPromise(times) {
return new Promise(function (resolve, reject) {
let arr = []
for (var i = 0; i < times; i++) {
arr.push(RNG.roll())
arr.sort(function(a, b) {return b - a})
}
resolve(arr[0] || 0)
})
}
}

function viewGachaResult(best) {
console.log(`YOUR BEST GATCHA ROLL RESULT IS ${best}`);
setTimeout(function () {
console.log(`YOUR BEST GATCHA ROLL RESULT IS ${best}`);
}, 1000)
}

function viewGachaFailure() {
Expand All @@ -35,17 +59,39 @@ RNG.gatchaRoll(0, function(result) { viewGachaResult(result) }); // output: 0
// RELEASE 1 TEST CASES
RNG.gatchaRollPromise(5)
.then(function(result) { viewGachaResult(result) })
.catch(function(err) { viewGachaFailure() };
.catch(function(err) { viewGachaFailure() });

// akan menampilkan di log: YOUR BEST GATCHA ROLL RESULT IS <angka antara 1-5>

RNG.gatchaRollPromise(0)
.then(function(result) { viewGachaResult(result) })
.catch(function(err) { viewGachaFailure() };
.catch(function(err) { viewGachaFailure() });

// akan menampilkan di log: YAKIN NGGAK MAU NGE-ROLL?


//
//
// RELEASE 2 PROMISE(S)

// code here...
//
RNG.gatchaRollPromise(5).then(function (result) {
RNG.gatchaRollPromise(result).then(function (result1) {
RNG.gatchaRollPromise(result1).then(function (result2) {
RNG.gatchaRollPromise(result2).then(function (result3) {
RNG.gatchaRollPromise(result3).then(function (result4) {
RNG.gatchaRollPromise(result4).then(function (result5) {
RNG.gatchaRollPromise(result5).then(function (result6) {
RNG.gatchaRollPromise(result6).then(function (result7) {
RNG.gatchaRollPromise(result7).then(function (result8) {
RNG.gatchaRollPromise(result8).then(function (result9) {
RNG.gatchaRollPromise(10).then(function (result11) {
console.log(result,result1,result2,result3,result4,result5,result6,result7,result8,result9);
})
})
})
})
})
})
})
})
})
})
})
80 changes: 80 additions & 0 deletions oop/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@

class Robot {
constructor(name, purpose) {
this.name = name
this.purpose = purpose
}
}

class WallE extends Robot{
constructor(name, purpose) {
super(name, purpose)
}
work() {
console.log('Wall-E cleans the planet');
}
}

class BayMax extends Robot{
constructor(name, purpose) {
super(name, purpose)
}
heal() {
console.log('Hi, I am BayMax, how may I help you?');
}
}

class AutoBot extends Robot{
constructor(name, purpose) {
super(name, purpose)
}
defend() {
console.log("AutoBot, let's roll!");
}
}

class robotFactory {
constructor() {

}
produceRobot(name, sum) {
let arr = []
for (var i = 0; i < sum; i++) {
if (name === 'wall-e') {
var data = new WallE(name, 'worker')
// return data
arr.push(data)
}
else if (name === 'baymax') {
var data = new BayMax(name, 'medic')
arr.push(data)
}
else if (name === 'autobot') {
var data = new AutoBot(name, 'defender')
arr.push(data)
}
}
return arr

}
}

const RobotFactory = new robotFactory()


let wall_e = RobotFactory.produceRobot('wall-e', 6);
let baymax = RobotFactory.produceRobot('baymax', 5);
let autobot = RobotFactory.produceRobot('autobot', 3);


for (var i = 0; i < wall_e.length; i++) {
wall_e[i].work()
}

for (var i = 0; i < baymax.length; i++) {
baymax[i].heal();
}

for (var i = 0; i < autobot.length; i++) {
autobot[i].defend();
}
13 changes: 13 additions & 0 deletions query/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"author": "Erwin W Ramadhan <[email protected]>",
"license": "ISC",
"dependencies": {
"cli-table": "^0.3.1",
"sqlite3": "^3.1.13"
}
}
12 changes: 12 additions & 0 deletions query/query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const sqlite3 = require('sqlite3').verbose()
const db = new sqlite3.Database('./database.db')

db.all(`select title, point, level, Players.name, Players.age,Players.gender from Status left join Players on Status.playerId = Players.id order by point desc`,
function (err,data) {
console.log(data);
})

db.all(`select count (*) as totalcard, Players.id, Players.name, Players.name, Players.age, Players.gender From Cards left join Players on Cards.playerId = Players.id where Players.gender ='Male' group by Players.name order by totalcard desc, Players.id asc limit 3`,
function (err, data) {
console.log(data);
})