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
type Person = | |
| { | |
firstName: string; | |
lastName: string; | |
isMarried: false; | |
} | |
| { | |
isMarried: true; | |
spouse: { | |
spouseFirstName: string; |
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
type Foo = { | |
prop1: { | |
value: string; | |
}; | |
prop2: { | |
value: string[]; | |
}; | |
prop3: { | |
value: number; | |
}; |
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
(async () => { | |
const promises = [ | |
new Promise(resolve => resolve(1)), | |
new Promise(resolve => resolve(2)), | |
new Promise(resolve => resolve(3)), | |
new Promise(resolve => resolve(4)), | |
new Promise(resolve => resolve(5)), | |
]; | |
const [...result ] = await Promise.all(promises.map(async p => { |
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 arr = [ | |
'a', 'b', 'c', 'd', 'e' | |
]; | |
const index = 2; // remove 'c' | |
const newarr = [ | |
...arr.slice(0, index), // [ 'a', 'b' ] | |
...arr.slice(index + 1), // [ 'd', 'e' ] | |
]; |
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 arr = [ | |
{ id: 0, name: 'john'}, | |
{ id: 1, name: 'mark' }, | |
{ id: 2, name: 'luke' }, | |
{ id: 3, name: 'peter' }, | |
]; | |
const newPerson = {id: 2, name: 'newPerson'}; | |
const index = arr.findIndex(val => val.id === newPerson.id); | |
console.log(index); |
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 a = { | |
id: 1, | |
name: { | |
lastName: '', | |
} | |
}; | |
const n = 'name'; | |
const b = { |