Skip to content

Instantly share code, notes, and snippets.

View knightazura's full-sized avatar
🏠
Working from home

Muhammad Izzuddin al Fikri knightazura

🏠
Working from home
  • Indonesia
  • 11:59 (UTC +07:00)
View GitHub Profile
@knightazura
knightazura / convert_type_properties.ts
Last active July 19, 2022 02:51
Convert typescript properties between `types` from snake case to camel case
type SnakeToCamelCase<S extends string> = S extends `${infer T}_${infer U}`
? `${T}${Capitalize<SnakeToCamelCase<U>>}`
: S;
type SnakeCaseType = {
first_name: string;
last_name: string;
age_in_number: number;
}
@knightazura
knightazura / array-random-pick.js
Last active January 11, 2021 03:17
Pick random element(s) from an array by given number
function randomPick(source = [], anyNumber = 1) {
if (source.length > 0) {
let result = [];
// Duplicate original array
let poppedArray = [].concat(source);
let currentLength = poppedArray.length;
for (let i = 0; i < anyNumber; i++) {
// Generate random number to pick an element inside array
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<input type="text" id="input-1" placeholder="Input 1">
<input type="text" id="input-2" placeholder="Input 2">