typestar

FizzBuzz in R

The classic screening exercise, done the way R prefers: over a vector.

for (i in 1:100) {
  if (i %% 15 == 0) {
    print("FizzBuzz")
  } else if (i %% 3 == 0) {
    print("Fizz")
  } else if (i %% 5 == 0) {
    print("Buzz")
  } else {
    print(i)
  }
}

Keywords and builtins used here

The run, in numbers

Lines
11
Characters to type
158
Tokens
64
Three-star pace
85 tpm

At the three-star pace of 85 tokens a minute, this run takes about 45 seconds.

Type this snippet

Step 2 of 5 in Flow & functions, step 6 of 20 in Language basics.

← Previous Next →

FizzBuzz in other languages