Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function addItem(state) {
const items = [...state.items]
const previous = state.items[state.items.length - 1]
const left = Math.round(Math.random()) === 1
const first = previous === undefined || previous.left !== left
const text =
lorem() +
(Math.round(Math.random()) ? '' : ` ${emoji.random({ count: 1 })}`)
if (previous !== undefined) previous.last = first
items.push({ key: state.items.length, text, left, first, last: true })
return { items }
}
function addItem(state) {
const items = [...state.items]
const previous = state.items[state.items.length - 1]
const left = Math.round(Math.random()) === 1
const first = previous === undefined || previous.left !== left
const text =
lorem() +
(Math.round(Math.random()) ? '' : ` ${emoji.random({ count: 1 })}`)
if (previous !== undefined) previous.last = first
items.push({ key: state.items.length, text, left, first, last: true })
return { items }
}