Skip to content
This repository has been archived by the owner on Jan 18, 2021. It is now read-only.

Commit

Permalink
Merge pull request #131 from akojif/master
Browse files Browse the repository at this point in the history
Create fizzbuzz-akf.js
  • Loading branch information
NullDev authored Oct 1, 2020
2 parents 1036978 + a12a2ff commit 3bdb207
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions JavaScript/fizzbuzz-akf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// FizzBuzz JavaScript solution (Readable, Extendable)
// Author: @akojif

FizzBuzz = function() {
var length = 100,
result = new Array(length);

for (i=0; i < length; i++) {
var seqNum = i + 1,
div3 = ((seqNum % 3) === 0),
div5 = ((seqNum % 5) === 0),

isFizzy = div3,
isBuzzy = !div3 && div5,
isFizBuzzy = div3 && div5,

word;

if (isFizzy) { word = "Fizz" };
if (isBuzzy) { word = "Buzz" };
if (isFizBuzzy) { word = "FizzBuzz" };

result[i] = word || seqNum;
word = null;
}

return result;
}

FizzBuzz().forEach( function(elm) { console.log(elm) })

0 comments on commit 3bdb207

Please sign in to comment.