const durations = { wholeRound: 142, placingBets: 25, lockingBet: 3, showingResult: 5, wholeTurn: 35, startingRound: 2, }; function proceed(time) { console.log(time) const { wholeRound } = durations; if (time === wholeRound) { console.log('check status'); } const remainingTime = time; time--; if (isChangingRoundTime(remainingTime)) { console.log('skip') return; } if (isStartingTime(remainingTime, durations)) { startTurn(remainingTime); } if (isStartingBetTime(remainingTime, durations)) { console.log('spb, generate') } if (isDuringBetTime(remainingTime)) { console.log('bet') } if (isStartingLockTime(remainingTime)) { console.log('lock') } if (isStartingGenerateResultWithPfTime(remainingTime)) { settleTurn(); } if (remainingTime === 0) { console.log('reset time') } } function startTurn(remainingTime) { const turn = getCurrentTurn(remainingTime); if (turn === 4) { console.log('reset round'); } else { console.log('reset turn'); } } function settleTurn() { console.log('settle') } function isDuringBetTime(remainingTime) { const { placingBets } = durations; const time = getCurrentTimeOfTurn(remainingTime); return time <= placingBets && time > 0; } function isStartingBetTime(remainingTime, durations) { const { placingBets } = durations; const time = getCurrentTimeOfTurn(remainingTime); return time === placingBets + 1; } function isStartingTime(remainingTime, durations) { return isStartingBetTime(remainingTime, durations); } function isStartingGenerateResultWithPfTime(remainingTime) { const time = getCurrentTimeOfTurn(remainingTime); return time === 0; } function isStartingLockTime(remainingTime) { const { lockingBet } = durations; const time = getCurrentTimeOfTurn(remainingTime); return time === lockingBet; } function isChangingRoundTime(remainingTime) { const numberOfTurnsPerRound = 4; const { wholeTurn } = durations; return remainingTime > wholeTurn * numberOfTurnsPerRound; } function getCurrentTimeOfTurn(remainingTime) { const { wholeTurn } = durations; const turn = calculateCurrentTurn(remainingTime, wholeTurn); return remainingTime - wholeTurn * (turn - 1); } function getCurrentTurn(remainingTime) { const { wholeTurn } = durations; return calculateCurrentTurn(remainingTime, wholeTurn); } function calculateCurrentTurn(remainingTime, wholeTurn) { return Math.min(Math.floor(remainingTime / wholeTurn) + 1,4); } [...Array(142 + 1).keys()].forEach(t => proceed(t))
Write, Run & Share NodeJS code online using OneCompiler's NodeJS online compiler for free. It's one of the robust, feature-rich online compilers for NodeJS language,running on the latest LTS version NodeJS 16.14.2. Getting started with the OneCompiler's NodeJS editor is easy and fast. The editor shows sample boilerplate code when you choose language as NodeJS and start coding. You can provide the dependencies in package.json
.
Node.js is a free and open-source server environment. Node.js is very popular in recent times and a large number of companies like Microsoft, Paypal, Uber, Yahoo, General Electric and many others are using Node.js.
Google chrome's javascript engine V8
and is pretty fast.Asynchronous
, event-driven
and works on single-thread model
thus eliminating the dis-advantages of multi-thread model.Express is one of the most popular web application framework in the NodeJS echosystem.
let moment = require('moment');
console.log(moment().format('MMMM Do YYYY, h:mm:ss a'));
const _ = require("lodash");
let colors = ['blue', 'green', 'yellow', 'red'];
let firstElement = _.first(colors);
let lastElement = _.last(colors);
console.log(`First element: ${firstElement}`);
console.log(`Last element: ${lastElement}`);
Following are the libraries supported by OneCompiler's NodeJS compiler.