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

Reynaldipane #2

Open
wants to merge 1 commit 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
112 changes: 100 additions & 12 deletions async/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,61 @@ class RNG {
const tiers = [1, 2, 3, 4, 5];
let num = Math.floor(Math.random() * 100) + 1;
let result = 'UNKNOWN';
if(num > 60) {
if (num > 60) {
result = tiers[0];
} else if(num > 40) {
} else if (num > 40) {
result = tiers[1];
} else if(num > 20) {
} else if (num > 20) {
result = tiers[2];
} else if(num > 5) {
} else if (num > 5) {
result = tiers[3];
} else {
result = tiers[4];
}

return result;
}

static gatchaRoll(times, callback) {
let max = 0;
if (times > 0) {
for (let i = 0; i < times; i++) {
let number = RNG.roll();
if (number > max) {
max = number;
}
}
}

setTimeout(function () {
callback(max);
}, 1000);

}

static gatchaRollPromise(times) {
let gatchaPromise = new Promise(function(resolve,reject) {
let max = 0;
if (times > 0) {
for (let i = 0; i < times; i++) {
let number = RNG.roll();
if (number > max) {
max = number;
}
}
setTimeout(function () {
resolve(max);
}, 1000);

} else {
setTimeout(function () {
reject(max);
}, 1000);
}
})

return gatchaPromise;
}
}

function viewGachaResult(best) {
Expand All @@ -28,24 +69,71 @@ function viewGachaFailure() {
}

// RELEASE 0 TEST CASES
RNG.gatchaRoll(5, function(result) { viewGachaResult(result) }); // output log sesuai hasil random terbaik
RNG.gatchaRoll(1, function(result) { viewGachaResult(result) }); // output log sesuai hasil random terbaik
RNG.gatchaRoll(0, function(result) { viewGachaResult(result) }); // output: 0
RNG.gatchaRoll(5, function (result) { viewGachaResult(result) }); // output log sesuai hasil random terbaik
RNG.gatchaRoll(1, function (result) { viewGachaResult(result) }); // output log sesuai hasil random terbaik
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() };
.then(function (result) {
viewGachaResult(result)
})
.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() };
.then(function (result) { viewGachaResult(result) })
.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) {
viewGachaResult(result)
return RNG.gatchaRollPromise(3)
})
.then(function (result){
viewGachaResult(result)
return RNG.gatchaRollPromise(6)
})
.then(function (result){
viewGachaResult(result)
return RNG.gatchaRollPromise(2)
})
.then(function (result){
viewGachaResult(result)
return RNG.gatchaRollPromise(1)
})
.then(function (result){
viewGachaResult(result)
return RNG.gatchaRollPromise(4)
})
.then(function (result){
viewGachaResult(result)
return RNG.gatchaRollPromise(6)
})
.then(function (result){
viewGachaResult(result)
return RNG.gatchaRollPromise(3)
})
.then(function (result){
viewGachaResult(result)
return RNG.gatchaRollPromise(5)
})
.then(function (result){
viewGachaResult(result)
return RNG.gatchaRollPromise(2)
})
.then(function (result){
viewGachaResult(result)
return RNG.gatchaRollPromise(1)
})
.catch(function (err) {
viewGachaFailure()
});
13 changes: 13 additions & 0 deletions oop/autobot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const Robot = require('./robot')

class Autobot extends Robot {
constructor(name,purpose) {
super(name,purpose);
}

defend() {
console.log("AutoBot, let's roll!");
}
}

module.exports = Autobot;
13 changes: 13 additions & 0 deletions oop/baymax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const Robot = require('./robot')

class Baymax extends Robot {
constructor(name,purpose) {
super(name,purpose);
}

heal() {
console.log('Hi, I am BayMax, how may I help you?');
}
}

module.exports = Baymax;
17 changes: 17 additions & 0 deletions oop/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const RobotFactory = require('./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();
}
24 changes: 24 additions & 0 deletions oop/robot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Robot {
constructor(name,purpose) {
this._name = name;
this._purpose = purpose;
}

set name(newName) {
this._name = newName;
}

set purpose(newPurpose) {
this._purpose = newPurpose;
}

get name() {
return this._name;
}

get purpose() {
return this._purpose;
}
}

module.exports = Robot;
35 changes: 35 additions & 0 deletions oop/robotfactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const Autobot = require('./autobot');
const Walle = require('./walle');
const Baymax = require('./baymax');


class RobotFactory {
constructor() {

}

static produceRobot(name, unit) {
let arrRobot = [];

if(name == "wall-e") {
for(let i = 0;i < unit;i++) {
let walle = new Walle()
arrRobot.push(walle)
}
} else if (name == "baymax") {
for(let i = 0;i < unit;i++) {
let baymax = new Baymax()
arrRobot.push(baymax)
}
} else if (name == "autobot") {
for(let i = 0;i < unit;i++) {
let autobot = new Autobot()
arrRobot.push(autobot)
}
}

return arrRobot;
}
}

module.exports = RobotFactory;
13 changes: 13 additions & 0 deletions oop/walle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const Robot = require('./robot')

class Walle extends Robot {
constructor(name,purpose) {
super(name,purpose);
}

work() {
console.log('Wall-E cleans the planet');
}
}

module.exports = Walle;
14 changes: 14 additions & 0 deletions query/query.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
RELEASE 0

SELECT status.title, status.point, status.level, players.name,players.age, players.gender
FROM status JOIN players ON status.playerId = players.id
ORDER BY status.level DESC

RELEASE 1

SELECT COUNT(*) as totalcard,
Players.id as playerId, Players.name, Players.age, Players.gender
FROM Players JOIN Cards ON Players.id = Cards.playerId
WHERE Players.gender = 'Male'
GROUP BY Players.id
ORDER BY totalcard DESC LIMIT 3