5 ms·
I consider this example fundamentally broken, in a non-obvious way that reflects, in my opinion, a poor API choice. <script> let numbers = $state([1, 2,
by alsiola 11mo ago
I consider this example fundamentally broken, in a non-obvious way that reflects, in my opinion, a poor API choice.
<script>
let numbers = $state([1, 2, 3, 4]);
function addNumber() {
numbers.push(numbers.length + 1);
}
const sum = numbers.reduce((x, y) => x + y, 0);
</script>
<p>{numbers.join(' + ')} = {sum}</p>
<button onclick={addNumber}>
Add a number
</button>