Skip to content

Commit

Permalink
feat: So you think you know fizzbuzz
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Nov 20, 2024
1 parent aa27aa9 commit 3137358
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
26 changes: 15 additions & 11 deletions sample/tdd/src/fizzBuzz.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
module.exports = (number) => {
if (number % 15 === 0) {
return 'fizzbuzz';
}
if (number % 3 === 0) {
return 'fizz';
}
if (number % 5 === 0) {
return 'buzz';
}
return number;
module.exports = {
simple: (number) => {
if (number % 15 === 0) {
return 'fizzbuzz';
}
if (number % 3 === 0) {
return 'fizz';
}
if (number % 5 === 0) {
return 'buzz';
}
return number;
},
optimized: (number) =>
[number, 'fizz', 'buzz', 'fizzbuzz'][3 & (19142723 >> (2 * (number % 15)))],
};
2 changes: 1 addition & 1 deletion sample/tdd/src/fizzBuzz.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const test = require('ava');
const fizzBuzz = require('../src/fizzBuzz.js');
const fizzBuzz = require('../src/fizzBuzz.js').simple;

test('should return the first value', (t) => {
t.is(fizzBuzz(1), 1);
Expand Down

0 comments on commit 3137358

Please sign in to comment.