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
function stockPicker(arr) { | |
// console.log(arr, "log risyandi: data array"); | |
let maxProfit = -1; | |
for (let index = 0; index < arr.length; index++) { | |
for (let jindex = index + 1; jindex < arr.length; jindex++) { | |
let profit = arr[jindex] - arr[index] | |
console.log(profit, "log risyandi: profit"); | |
if (profit > maxProfit) { | |
maxProfit = profit | |
// console.log(maxProfit, "log risyandi: maxProfit"); |
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 now = new Date().getTime(); // current date | |
const futureDate = new Date('7 Feb 2023 16:40:00').getTime(); // setup time left | |
const timeleft = futureDate - now; | |
const days = Math.floor( timeleft / (1000 * 60 * 60 * 24)); | |
const hours = Math.floor((timeleft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); | |
const minutes = Math.floor((timeleft % (1000 * 60 * 60)) / (1000 * 60)); | |
const seconds = Math.floor((timeleft % (1000 * 60)) / 1000); |
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
/** step by step | |
* 1. Get time that passed since Unix Epoch using Date() constructor with getTime(), | |
* 2. calculate the difference between current date and future date, | |
* 3. convert milliseconds to seconds, minutes, hours, etc. | |
* 4. calculate remaining time using modulo (%) operations and rounding the result using Math.floor() to get approximate result. | |
**/ | |
const now = new Date().getTime(); // current date | |
const futureDate = new Date('27 Jan 2030 16:40:00').getTime(); // setup time left |
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
function dateDiff(startDate, endDate) { | |
console.log(new Date(startDate), "startDate"); // since user register | |
console.log(new Date(endDate), "endDate"); // date of voucher expired | |
const diffInMs = new Date(endDate) - new Date(startDate); | |
const diffInDays = diffInMs / (1000 * 60 * 60 * 24); | |
console.log(diffInDays, "diffInDays"); | |
if (diffInDays === 5) { | |
console.log("voucher disappear"); |
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
// Set initial countdown time to 60 seconds | |
var countdown = 60; | |
// Update the timer display every second | |
setInterval(function() { | |
countdown--; | |
var seconds = countdown % 60; | |
var minutes = Math.floor(countdown / 60); | |
// Add leading zero to seconds if less than 10 |
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
<template> | |
<div class="iframe-container"> | |
<iframe | |
class="iframe" | |
:src="iframeUrl" | |
allowfullscreen | |
scrolling="yes" | |
ref="iframe" | |
@load="handleIframeLoad" | |
></iframe> |
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
// Go program to illustrate how | |
// to put a goroutine to sleep | |
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
// Here, the value of Sleep function is zero |
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
function generateID() { | |
const date = new Date(); | |
const day = ("0" + date.getDate()).slice(-2); | |
const month = ("0" + (date.getMonth() + 1)).slice(-2); | |
const year = date.getFullYear().toString().substr(-2); | |
const random = Math.random().toString(36).substring(2, 6).toUpperCase(); | |
return `INV-DOL-${day}${month}${year}-${random}`; | |
} | |
const newID = generateID(); |
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
package main | |
import ( | |
"bufio" | |
"fmt" | |
"io" | |
"os" | |
"strings" | |
"time" | |
) |
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
function convertToSnakeCase(text) { | |
let snakeCaseText = ""; | |
const specialChars = `!"#$%&'()*+,-./:;<=>?@[\\]^\`{|}~`; | |
for (let index = 0; index < text.length; index++) { | |
const char = text[index]; | |
if (char === "_" || char === " ") { | |
snakeCaseText += "_"; // Preserve underscores and change spaces to underscores | |
} else if (!specialChars.includes(char)) { |