Doraemon pouch of snippets, tricks and hacks
// falsy: false,undefined,null,0,NaN,''
// not falsy: {}, [],'0','false',-1
x ? x : y => x || y
x ? false : true => !x
x ? true : false => !!x
const people = [
{
id:1,
name:'alice',
job:'engineer'
},
{
id:2,
name:'bob',
job:'engineer'
},
{
id:3,
name:'charlie',
job:'doctor'
}
]
people.some(p=>p.id===1) //true
people.every(p=>p.job==='doctor') //true
people.find(p=>p.job==='engineer')// {alice}
people.filter(p=>p.name==='engineer')// [{alice},{bob}]
people.sort((a,b)=>a.name<b.name)
/* Sort by name
[ { id: 3, name: 'charlie', job: 'doctor' },
{ id: 2, name: 'bob', job: 'engineer' },
{ id: 1, name: 'alice', job: 'engineer' } ]
*/
document.designMode='on'
status-code:200
or (NOT)-method:GET