FizzBuzz Map vs Reduce

Benchmark created on


Description

FizzBuzz using Array.map vs Array.reduce

Test runner

Ready to run.

Testing in
TestOps/sec
Map
const fizzbuzz = [...Array(100)].map((val, idx) => {
  const value = idx + 1
  if (!(value % 3) && !(value % 5)) {
  	return 'FizzBuzz'
  }
  if (!(value % 3)) {
  	return 'Fizz'
  }
  if (!(value % 5)) {
  	return 'Buzz'
  }
  return value
}).join('\n')
ready
Reduce
const fizzbuzz = [...Array(100)].reduce((agr, val, idx) => {
  const value = idx + 1
  if (!(value % 3) && !(value % 5)) {
    return agr += 'FizzBuzz'
  }
  if (!(value % 3)) {
    return agr += 'Fizz'
  }
  if (!(value % 5)) {
    return agr += 'Buzz'
  }
  return agr + value
}, '')
ready
Map No Destructure
const fizzbuzz = Array.apply(0, Array(100)).map((val, idx) => {
  const value = idx + 1
  if (!(value % 3) && !(value % 5)) {
    return 'FizzBuzz'
  }
  if (!(value % 3)) {
    return 'Fizz'
  }
  if (!(value % 5)) {
    return 'Buzz'
  }
  return value
}).join('')
ready
Reduce No Destructure
const fizzbuzz = Array.apply(0, Array(100)).reduce((agr, val, idx) => {
  const value = idx + 1
  if (!(value % 3) && !(value % 5)) {
    return agr += 'FizzBuzz'
  }
  if (!(value % 3)) {
    return agr += 'Fizz'
  }
  if (!(value % 5)) {
    return agr += 'Buzz'
  }
  return agr + value
}, '')
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.