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
/** | |
* range of available symbols for maximum radix (i.e. 61) | |
* @type {string} | |
*/ | |
const range = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
/** | |
* converts JavaScript number from other bases to decimal | |
* | |
* @param {number} value number to be converted |
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
import React, { useState } from "react"; | |
function Timer(props) { | |
const { countdownState } = props; | |
let [minutes, setMinutes] = useState(0); | |
let [seconds, setSeconds] = useState(10); | |
switch (countdownState) { | |
case 0: |
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
//Note: kode ini hanya untuk ilustrasi metode brute-force | |
function getAngle({ hour, minute, second, miliSecond }) { | |
//Semua perhitungan di bawah dikalikan 10000 untuk menyimpan akurasi | |
//dari operasi bilangan. Nanti akan dibagi 10000 lagi. | |
//Cari proporsi sudut menit, detik, dan milidetik dalam satu tick jarum menit | |
const minuteHand = | |
minute * 60000 + (second * 10000) / 10 + (miliSecond * 10000) / 10000; |
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
if(b===9) { | |
return -1 | |
} else { | |
return 0 | |
} |
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
//array input | |
let input = [9, -1, 8, 3, -2, 9, 4, -3, 9] | |
//bilangan yang ingin kita pindahkan ke belakang | |
const numberToMove = 9 | |
input.sort((a,b) => { | |
if(b===9) { | |
return -1 | |
} else { | |
return 0 |
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
//array input | |
let input = [9, -1, 8, 3, -2, 9, 4, -3, 9] | |
//bilangan yang ingin kita pindahkan ke belakang | |
const numberToMove = 9 | |
//array nines berisi bilangan dalam input yang sama dengan 9 | |
const nines = input.filter((number) => number === numberToMove) | |
//array nines berisi bilangan dalam input yang tidak sama dengan 9 | |
const notNines = input.filter((number) => number !== numberToMove) |
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
//penulisan dengan arrow function | |
(number, index) => { | |
if(number === numberToMove) { | |
input.splice(index, 1) | |
input.push(number) | |
} | |
} | |
//fungsi di atas ekuivalen dengan fungsi di bawah |
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
//array input | |
let input = [9, -1, 8, 3, -2, 9, 4, -3, 9] | |
//bilangan yang ingin kita pindahkan ke belakang | |
const numberToMove = 9 | |
//gunakan loop forEach untuk mengecek tiap element | |
input.forEach((number, index) => { | |
//kalau element sama dengan 9 | |
if(number === numberToMove) { | |
//hapus dia dari array |
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
... | |
do { | |
var hasil = []; | |
var mulai = max; | |
//mulai isi array dengan bilangan pertama | |
do { | |
//method unsift mengisi element dari bagian depan array | |
hasil.unshift(mulai); | |
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 jumlah(array) { | |
const nilaiAwal = 0 | |
//gunakan fungsi reduce untuk mengakumulasi | |
//hasil penjumlahan dari semua element | |
return array.reduce(function(jumlah, nilai) { | |
return jumlah + nilai | |
}, nilaiAwal) | |
} |
NewerOlder