for(let i = 1; i < 101; i++){ let w = ''; for(key in rules){ if( i % key == 0){ w += rules[key]; } } if(w) document.write(w+" "); else document.write(i+" ");
It is user's entire function design. user assumes the question "what if I add/want to add a new rule later?" Any maintainer can come in and see they simply need to update the set of rules and that's all.
Henry Johnson
why the fuck would you have maintainers for fizzbuzz? you're off your noggin you fucking unit.
Juan White
This reminds me my feet are cold and wet rn :(
Christian Thomas
You're a real dumbass aren't ya? Fizzbuzz is just proof of concept.
(1..100).each {|i| puts (s = "#{'Fizz' if (i%3)==0}#{'Buzz' if (i%5)==0}").empty? ? i : s }
Alexander Walker
No
Andrew Bell
only java faggots who overcomplicate simple stuff would think something so retarded. fizzbuzz is literally an entry-level programming question, its only point is to see if you can write barely comprehensible code or not. you obviously cannot.
parseNum :: [(Int, String)] -> Int -> String parseNum [] _ = "" parseNum ((key,val):xs) i | i `mod` key == 0 = val ++ (parseNum xs i) | otherwise = parseNum xs i
parsedInput = parseNum rules num retString = if parsedInput == "" then (show num) else parsedInput
main = print (fizzbuzz [1..100])
Benjamin Stewart
I don't get it
Joseph Sanders
Relevant enough, I just wrote a bubble sort program for the first time yesterday. Did I get the job? PROGRAM BUBBLESORT INTEGER n, sorted, tmp INTEGER t(10)
c Parses file into array OPEN (log, FILE='array') DO n = 1, 10 READ (log, *) t(n) ENDDO CLOSE (log)
c Sort DO WHILE (sorted .EQ. 0) sorted = 1 DO n = 1, 9 IF (t(n) .GT. t(n + 1)) THEN tmp = t(n) t(n) = t(n + 1) t(n + 1) = tmp sorted = 0 ELSE CONTINUE ENDIF ENDDO ENDDO
c Print sorted array DO n = 1, 10 PRINT *, t(n) ENDDO
END PROGRAM BUBBLESORT
Jackson Sanchez
wow kid you know how to use a for loop and you made an object wow kid, you some kind of tech whizz huh. i work at a fortune 500 company and i've been looking for bright sparks like you. listen kid, i need ya on my team. you're gonna make me rich with code like that
Cooper Ramirez
nu-Jow Forums ladies and gentlemen
Noah Wright
On our company, we value people that are able to learn fast so, i want you to write a fizzbuzz routine for the computer related.
But the only commands you can use are for,next, data, read, poke, def usr and usr()
there is a loop that needs N time and inside there is another loop that takes 2 steps so it needs 2*N times to finish. Stop browsing Jow Forums if you are such a brainlet
Evan Jackson
O(n) == O(2n)
>N time >2 steps
What about using the proper terminology?
James Diaz
That's the joke
Hudson Baker
Use rules.forEach, retard
Joshua Davis
>Wouldnt it be faster to check if i is in rules via the map rather than iterating through rules every i? You're not checking whether i is in the map, you're checking which, if any, values in the map are divisors of i. As far as I know, the only way to avoid iterating through the loop would be factorizing i and creating a list of its divisors, but that would be very inefficient in a realistic use-case.
Cooper Nelson
You(r) stupid
Evan Green
whart is this language, why is a simple bubble sort so big?
Joseph Morales
what does poke def usr next and usr() mean?
Anthony Stewart
It is a common follow up to the interview question. To any interview question, really
John Wilson
Looks almost like Pascal or a bit COBOL-like but there's enough difference to make me think it's not either of these, but of a similar ancient lineage. Fortran?
Gabriel Myers
fun concept, remade in haskell import qualified Data.IntMap as M type Rules = M.IntMap String
fizzer :: Rules -> Int -> String fizzer r i | null prep = show i | otherwise = prep where prep = M.foldr (++) "" . M.filterWithKey (\k _ -> i `rem` k == 0) $ rules
function toCharArray(str) { const length = str.length; if (length < 1) { return []; } let i = 0; const result = []; do result[i] = str.charCodeAt(i); while(++i < length); return result; }
function* fizzBuzz(limit = 100) { let i = 0; while(++i
Dominic Miller
that's the very reason I hate most people, just cause you heard about Big O notation you think you know how to calculate an algorithm...
Dominic Rogers
let ? as in brainlet?
Landon Hernandez
O(2n) is O(n), you fucking idiot.
Christian Wilson
: RULE ( addr max -- ) CREATE 0 , , , ( count max addr ) DOES> ( -- f ) DUP @ 1+ OVER 1 CELLS + @ OVER R IF DROP 0 OVER 2 CELLS + @ EXECUTE THEN SWAP ! R> ;
Not enough abstraction class FizzBuzz{ constructor(fizz, end, start){ this.start = start || 0 this.end = end || 100 this.fizz = fizz this.i = 0 } static Fizz(n, obj){ let item = '' for(let p in obj) if(!(n % p)) item += obj[p] return item || n } * generator(){ while(this.i++ < this.end) yield this.constructor.Fizz(this.i, this.fizz) } } var FB = new FizzBuzz({3: 'Fizz', 5: 'Buzz'}, 100) var FBGen = FB.generator() for(i of FBGen) console.log(i)
Julian Lewis
Just a guess, but I have seen it for that purpose a bunch. People don't know how to open Dev tools or something, so it's the console.log of the jsfiddle and related sites crowd
Matthew Smith
JavaScript is horrible, I have to learn node.js for college, everytime I start something in JavaScript I start getting more and more suicidal, why did JavaScript become ao mainstream?
The main focus of my degree is Networking, but I have these extra filler classes like UI (by UI they mean webdesign) and Data Science (R) which bore me to death, I have the UI exam tomorrow and I am kneedeep in ShitScript. It's not difficult per se, but it's genuinely a SHIT language. Arrays in JavaShit are basically black holes, you can throw in whatever you want and it's accepted. You can stick a string in the 100th index, an integer in the 240th index and leave the rest empty and it doesn't care, the length is now 241 and it's filled with "undefined" besides the string in 100 and the integer in 240. Hating JavaScript is not a meme guys, it's really shit.
Landon Robinson
Also, I forgot to mention to array.sort() sorts arrays alphabetically, no matter what's in the array, to make it sort by value, you have to use something like array.sort(function (a,b){return a-b});