Skip to content

Instantly share code, notes, and snippets.

@incon
Created November 28, 2017 07:42
Show Gist options
  • Save incon/e3caa3576db7caaefd167ae54a8df31b to your computer and use it in GitHub Desktop.
Save incon/e3caa3576db7caaefd167ae54a8df31b to your computer and use it in GitHub Desktop.
React FizzBuzz
import React from "react";
const Number = props => <span>{props.value}</span>;
const Fizz = () => <span>Fizz</span>;
const Buzz = () => <span>Buzz</span>;
export const FizzBuzz = () => {
return [...Array(100).keys()].map(v => {
v++;
return (
<div key={v}>
{v % 5 !== 0 && v % 3 !== 0 && <Number value={v} />}
{v % 3 === 0 && <Fizz />}
{v % 5 === 0 && <Buzz />}
</div>
);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment