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
[ | |
{ | |
"countryName": "Afghanistan", | |
"phoneCode": 93, | |
"countryCode": "AF / AFG" | |
}, | |
{ | |
"countryName": "Albania", | |
"phoneCode": 355, | |
"countryCode": "AL / ALB" |
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
/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/ |
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
***Here is the code for converting "image source" (url) to "Base64".*** | |
let url = 'https://cdn.shopify.com/s/files/1/0234/8017/2591/products/young-man-in-bright-fashion_925x_f7029e2b-80f0-4a40-a87b-834b9a283c39.jpg' | |
const toDataURL = url => fetch(url) | |
.then(response => response.blob()) | |
.then(blob => new Promise((resolve, reject) => { | |
const reader = new FileReader() | |
reader.onloadend = () => resolve(reader.result) | |
reader.onerror = reject | |
reader.readAsDataURL(blob) |
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
export const capitalizeFirstChar = (char) => { | |
const result = char | |
.split(" ") | |
.map((c) => { | |
const first = | |
c.slice(0, 1) === "x" ? c.slice(0, 1) : c.slice(0, 1).toUpperCase(); | |
const leas = c.slice(1); | |
return `${first}${leas}`; | |
}) |
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 filtered = [1, 2, 3, 4].filter( | |
function(e) { | |
return this.indexOf(e) < 0; | |
}, | |
[2, 4] | |
); | |
console.log(filtered); // [1,3] |
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 numberWithDots(x) { | |
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."); | |
} |
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 date1 = new Date('12/31/2020'); | |
const date2 = new Date(); | |
const difference = date1.getTime() - date2.getTime(); | |
const days = Math.abs(Math.ceil(difference / (1000 * 3600 * 24))); | |
console.log(days + ' days to go to new year!'); |
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
// contoh ada array hewan = ["ayam", "bebek", "lele"] | |
// ingin membuat array yang isinya index dari berapa panjang array hewan | |
// cara 1 | |
Array.from(Array(hewan.length).keys()) | |
//=> [0, 1, 2] | |
// cara 2 | |
[...Array(hewan.length).keys()] | |
//=> [0, 1, 2] |
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 colors = ['red', 'blue', 'yellow', 'purple', 'green', 'grey', 'brown', 'white', 'black'] | |
function chunkArray(myArray, chunk_size) { | |
let index = 0 | |
let arrayLength = myArray.length | |
let tempArray = [] | |
for (index = 0; index < arrayLength; index += chunk_size) { | |
let myChunk = myArray.slice(index, index + chunk_size) | |
tempArray.push(myChunk) |
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
/** | |
* Get YouTube ID from various YouTube URL | |
* @author: takien | |
* @url: http://takien.com | |
* For PHP YouTube parser, go here http://takien.com/864 | |
*/ | |
function YouTubeGetID(url){ | |
var ID = ''; | |
url = url.replace(/(>|<)/gi,'').split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/); |
NewerOlder