2 edited body
source | link

Return intermediate result

You know that using the comma operator you can execute a sequence of expressions returning the last value. But abusing the literal array sintaxsyntax, you can return any intermediate value. It's useful in .map() for instance.

// capitalize words
// f is a flag indicating if prev char is space
[...x].map(c=>(f?c=c.toUpperCase():0,f=c<'!',c),f=1).join('')

// shortened to ...
[...x].map(c=>[f?c.toUpperCase():c,f=c<'!'][0],f=1).join('')

Return intermediate result

You know that using the comma operator you can execute a sequence of expressions returning the last value. But abusing the literal array sintax, you can return any intermediate value. It's useful in .map() for instance.

// capitalize words
// f is a flag indicating if prev char is space
[...x].map(c=>(f?c=c.toUpperCase():0,f=c<'!',c),f=1).join('')

// shortened to ...
[...x].map(c=>[f?c.toUpperCase():c,f=c<'!'][0],f=1).join('')

Return intermediate result

You know that using the comma operator you can execute a sequence of expressions returning the last value. But abusing the literal array syntax, you can return any intermediate value. It's useful in .map() for instance.

// capitalize words
// f is a flag indicating if prev char is space
[...x].map(c=>(f?c=c.toUpperCase():0,f=c<'!',c),f=1).join('')

// shortened to ...
[...x].map(c=>[f?c.toUpperCase():c,f=c<'!'][0],f=1).join('')
1
source | link

Return intermediate result

You know that using the comma operator you can execute a sequence of expressions returning the last value. But abusing the literal array sintax, you can return any intermediate value. It's useful in .map() for instance.

// capitalize words
// f is a flag indicating if prev char is space
[...x].map(c=>(f?c=c.toUpperCase():0,f=c<'!',c),f=1).join('')

// shortened to ...
[...x].map(c=>[f?c.toUpperCase():c,f=c<'!'][0],f=1).join('')