Would you hire me?

let rules = {
3: "fizz",
5: "buzz"
}

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+"
");

}

Attached: DcWw4B0V4AAXMys.jpg (400x514, 21K)

I would hire you to suck my dick, but only if you were wearing all the clothes in the image and nothing else.

No thanks!

nice solution but somebody submitted a version that works in O(n) time.

OP's is O(n) though

I wouldn't hire someone putting that much complexity in fizzbuzz because that would mean he's a memer and can't do anything else.

what's the benefit, other than being able to add more rules later, of having that map over a few if statements?

Wouldnt it be faster to check if i is in rules via the map rather than iterating through rules every i?

OP what are you doing

O(2n)

kek

> document.write
> document.write
> document.write
why are you like this?

Attached: do you have any idea what you're doing.jpg (750x756, 53K)

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.

why the fuck would you have maintainers for fizzbuzz? you're off your noggin you fucking unit.

This reminds me my feet are cold and wet rn :(

You're a real dumbass aren't ya? Fizzbuzz is just proof of concept.

>t. Southern Hemisphere nigger

Attached: 1507259674652.png (300x300, 9K)

How's this for a Ruby solution:

(1..100).each {|i| puts (s = "#{'Fizz' if (i%3)==0}#{'Buzz' if (i%5)==0}").empty? ? i : s }

No

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.

I just choked on my panini bread

fizzbuzz :: [Int] -> [String]
fizzbuzz [] = []
fizzbuzz (num:xs) = [retString] ++ fizzbuzz xs
where rules = [(3, "fizz"), (5, "buzz")]

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])

I don't get it

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

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

nu-Jow Forums ladies and gentlemen

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()

Attached: MSX Sharp X1.jpg (600x759, 56K)

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

O(n) == O(2n)

>N time
>2 steps

What about using the proper terminology?

That's the joke

Use rules.forEach, retard

>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.

You(r) stupid

whart is this language, why is a simple bubble sort so big?

what does poke def usr next and usr() mean?

It is a common follow up to the interview question. To any interview question, really

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?

fun concept, remade in haskell
import qualified Data.IntMap as M
type Rules = M.IntMap String

rules :: Rules
rules = M.fromList $ [
(3,"Fizz"),
(5,"Buzz")
]

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

fizzbuzz = mapM_ (putStrLn . fizzer rules) [1..100]

oh shiet didn't notice already made it in haslel

fixed.

Attached: image.png (400x514, 88K)

>replace socks with programming socks
fixed

>fortran
ding ding ding

a ringing terminal for you. But it's a "new" implementation (no label in the DO loop), so Fortran 90 upwards.

I feel old.

That's Fortran 77, I'm just new to the do loop and forgot that part. I ended it like you'd end a do while loop.

PROGRAM BUBBLESORT
INTEGER n, sorted, tmp
INTEGER t(10)

c Parses file into array
OPEN (log, FILE='array')
DO 10 n = 1, 10
READ (log, *) t(n)
10 CONTINUE
CLOSE (log)

c Sort
DO WHILE (sorted .EQ. 0)
sorted = 1
DO 20 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
20 CONTINUE
ENDDO

c Print sorted array
DO n = 1, 10
PRINT *, t(n)
ENDDO

END PROGRAM BUBBLESORT

"use strict";
const moduloTestCases = (
new Map()
.set(3, toCharArray("Fizz"))
.set(5, toCharArray("Buzz"))
);

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

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...

let ?
as in brainlet?

O(2n) is O(n), you fucking idiot.

: 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> ;

: .FIZZ ." Fizz" ; ' .FIZZ 3 RULE FIZZ?
: .BUZZ ." Buzz" ; ' .BUZZ 5 RULE BUZZ?

: FIZZER 101 1 DO CR FIZZ? BUZZ? OR INVERT IF I . THEN LOOP ;

So he can see the answers in jsfiddle

result = [ ...result, text];

Yum.

Attached: 1525587163024.gif (194x191, 39K)

Is this a language wizards use?

I like the rules idea.

rules = {
3 => 'fizz',
5 => 'buzz'
}

(1..100).each do |i|
o = rules.inject('') {|memo, (k, v)| (i % k).zero? ? memo

>all these non-enterprise languages
enum FizzbuzzRules {
FIZZ( i -> i%3 == 0 ? "fizz" : "";), BUZZ( i -> i%5 == 0 ? "buzz" : "";)

private final Function rule;

public FizzbuzzRules(Function rule) {
this.rule= rule;
}

public Function getRule() {return rule;}
}

public void printFizzBuzz() {
IntStream.range(1, 100)
.map(this::applyFizzBuzzRules)
.forEach(System.out::println);
}

private String applyFizzBuzzRules(int i) {
return FizzbuzzRules.values().stream()
.map(FizzbuzzRules::getRule)
.map(rule -> rule.apply(i))
.collectingAndThen(Collectors.joining(), result -> result.length() > 0 ? result : i);
}

How do you know?

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)

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

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?

Attached: downloadfile-1.jpg (474x354, 19K)

Might as well kys now, unless your going embedded you'll be using it.

Attached: received_121892478691647.png (433x215, 22K)

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.

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});