Writing FizzBuzz in WebAssembly

FizzBuzz is a programming challenge that requires a user to take in a positive number loop from 1 to a chosen number and print out the results based on the following criteria:

  • If the number is divisible by 3, then print Fizz
  • If the number is divisible by 5, then print Buzz
  • If the number is divisible by 15, then print FizzBuzz

Let's go ahead and kick this off by getting our JavaScript environment ready. The following code should look familiar, except for our new logging function:

const memory = new WebAssembly.Memory({initial : 1});const storeByte = new Int32Array(memory.buffer, 0, 1);   function consoleLogString(offset, length) {    const bytes = new Uint8Array(memory.buffer, offset, length); const string = new ...

Get Hands-On JavaScript High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.