Fork me on GitHub
#beginners
<
2016-06-09
>
andrewzhurov11:06:18

Hello, guys 🙂

andrewzhurov11:06:04

Could someone give me a hint where I can find interview questions on jun-mid position ?

andrewzhurov11:06:14

(Senior's will fit too, though. Not mind to scary myself a little bit)

volrath16:06:57

Hi guys, I spent some time over last weekend building my first little project in ClojureScript, with the motivation of trying out as much things as a could. I built a Pong game in 3D using three.js: http://volrath.github.io/clojurescript-pong-3d/, which is copied from this tutorial: http://buildnewgames.com/webgl-threejs/ but ported to cljs. Here's the current code and possible plans for the future: https://github.com/volrath/clojurescript-pong-3d I know this is a big thing to ask, but if anyone have the time to check out the code and give me a quick, short review, it would be highly appreciated. I'm looking for big picture stuff: comments on code organization, best practices, possible bad habits I'll be having, more functional approaches to solve things, etc. Anyway, feel free to play the game a little bit and have fun with it, although right now the opponent is way easy to beat 🙂

seancorfield19:06:40

@brownmoose3q: Not sure what you’re looking for… are you assuming companies that hire Clojure devs have standard "quiz" type tech questions about Clojure? I doubt that’s true.

seancorfield19:06:36

A lot of companies now realize that "tech quizzes" don’t really work in interviews.

seancorfield19:06:46

When we hire at World Singles, we don’t have a "tech quiz". Instead we generally work from a mind map that covers a broad set of areas that we want to get a candidate talking about. We want to hear what gets them excited about projects, what they dislike about projects, how they work on a day-to-day basis (their design, test, code workflows). We ask about what they like and dislike about their current technology stack and if/why they’d want to use a different stack.

seancorfield19:06:42

If you want to show someone you can solve Clojure problems, do http://4clojure.com puzzles and get a ranking there 🙂

yogidevbear20:06:44

I'm trying to wrap my head around something with the immutable nature of stored values. What is the best approach for something like looping over items in a list and adding them up within function, e.g:

(fn[lst]
  (dotimes [x (count lst)]
    logic here? ))

yogidevbear21:06:31

Where lst is something like '(1 3 14 2 9 3 5)

dmbennett21:06:46

(apply + '(1 3 14 2 9 3 5))

dmbennett21:06:37

map is also a good way to apply a function to every member of a list

dmbennett21:06:01

depending on the use case

yogidevbear21:06:17

What if I wanted to sum odd numbers only?

yogidevbear21:06:31

e.g. 1 + 3 +9 + 3 + 5

cory21:06:49

(apply + (filter odd? numbers))

cory21:06:49

The general pattern of iterating over a list (like in an imperative for loop) usually comes down to map filter and reduce and mixing them up together in a functional language

cory21:06:38

+ is a kind of reduce in this case, you can think of it as iterating over the list and making a new thing by applying a function to some final value (the sum so far) and some current value (the item we’re looking at right now). reduce is used on a list when you want to change the shape of a structure (in this case, from a list of numbers to just one number). map is used when you want to keep items in the same kind of structure, but want to change each one (like if you wanted to turn a list of user ids into a list of usernames, maybe). filter is used when you want to keep only some of the items in that structure (like if you want a new list with only odd numbers).

yogidevbear21:06:44

I'm starting to love FP and Clojure 🙂

cory21:06:06

🙂 it is pretty sweet, for sure

yogidevbear21:06:17

So I'm testing this (fn[lst] (println (apply + (filter odd? lst)))) and it outputs a number (the correct number) followed by a nil

yogidevbear21:06:39

Any idea why/where the nil is coming from?

cory21:06:55

println actually is returning nil

yogidevbear21:06:14

Been using println through all the previous tests and this is the first time nil is displaying

yogidevbear21:06:57

Took the println part out and just used (fn[lst] (apply + (filter odd? lst)))

cory21:06:03

Cool, that’ll do it.

cory21:06:37

No problem, have fun on your Clojure journey!

dmbennett21:06:07

is there a quick function for returning filtered items from a lazy-seq with their original index?

dmbennett21:06:18

or just the index values?

dorab21:06:21

@dmbennett: check out keep-indexed

cory21:06:17

i wonder if i’ll ever stop being surprised by the depth of the core functions

dorab21:06:00

@dmbennett: or, perhaps, map-indexed

dmbennett22:06:23

both of those take an index, but don’t return the index position. I just want to return the index position

cory22:06:06

@dmbennett i think what dorab is suggesting is something along these lines

(map first (filter (fn [[_ x]] (odd? x)) (map-indexed vector '(1 2 3 4 5))))

cory22:06:33

There is usually a better way than the ones I think of, but that’s how I would try 🙂

cory22:06:37

@dmbennett a for comprehension is probably better in this case actually

(for [[index item] (map-indexed vector '(1 2 3 4 5))
      :when (odd? item)]
      index)