Skip to content

Instantly share code, notes, and snippets.

View KevinPy's full-sized avatar

Kevin KevinPy

View GitHub Profile
### Keybase proof
I hereby claim:
* I am kevinpy on github.
* I am kevinpy (https://keybase.io/kevinpy) on keybase.
* I have a public key whose fingerprint is 1C8F 5463 751B 4E35 3BBE 736D BFC3 E7C4 5A53 503C
To claim this, I am signing this object:
@KevinPy
KevinPy / noob-request.js
Created November 25, 2021 10:29
Open Stackoverflow auto when your request fail
try {
// Do something
}
catch (error) {
const url = `https://stackoverflow.com/search?q=[js]+${error.message}`;
window.open(url, '_blank');
}
@KevinPy
KevinPy / filter.js
Created March 29, 2019 16:57
Filter unique values
const array = [1, 1, 2, 3, 5, 5, 1]
const uniqueArray = [...new Set(array)];
console.log(uniqueArray); // [1, 2, 3, 5]
@KevinPy
KevinPy / Horizontal2Vertical.js
Created November 28, 2018 14:43
Transform Array of Array => Horizontal to Vertical
const arr = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
];
const rotate = arr.reduce((value, row) => {
return row.map((_, i) => {
return [...(value[i] || []), row[i]];
});
@KevinPy
KevinPy / mix_array_object.js
Created March 22, 2018 08:14
[JS] Mix Arrays / Object
////////////////////////////////////////////////////////////////
/* Combine 2 arrays in Object with key */
////////////////////////////////////////////////////////////////
const arr1 = ['01', '02', '03'];
const arr2 = ['10', '20', '30'];
let obj = arr1.map((item, i) => {
return {
arr1: item,
arr2: arr2[i]