konijn
  • Member for 9 years, 6 months
  • Last seen this week
  • Lyon, France
Grouping elements in array by multiple properties
Accepted answer
64 votes

I felt compelled to write that you probably should combine forEach and map with the answer of Alexey Lebedev. function groupBy( array , f ) { var groups = {}; array.forEach( function( o ) { ...

View answer
Check whether address criteria contain only certain fields or more
Accepted answer
35 votes

I would be compelled to write a helper that accepts a variable number of address fields and and returns true if all of the address fields are not null and not empty. private boolean isShortAddress(...

View answer
Possible antipattern: looping until a search condition is met
26 votes

Possible anti-pattern is quite an understatement. There is so much wrong with this that I had to get creative to get over it. The suggestion by @dusky are excellent on how to fix it, but I did not ...

View answer
Managing network address information
Accepted answer
20 votes

From perusing your code a few times: Custom event abuse While it's very cool to have custom events, I would simply remove this extra layer of logic. It does not make sense to call $(networkInfo)....

View answer
WebTorrent player
Accepted answer
18 votes

After reviewing, I came up with these observations: You really should not do inline scripts, put this in a separate .js file No meaningless comments, you should remove //Torrent ID Variables should ...

View answer
Generating all combinations of an array
17 votes

I prefer your approach much better than a recursive approach, especially when larger lists are being processed. Some notes: I like the name powerSet as per @200_success You do not need to check for ...

View answer
Logs 'Fizz' for multiples of three, 'Buzz', for multiples of 5, and 'Fizz Buzz' for multiples of 3 & 5
15 votes

A short review; You don't need the array, you could just use i Part of the challenge is to realize that you only have to check for 3 and 5 i is a good short variable, I would go for num -> n or ...

View answer
Verifying password strength using JavaScript
15 votes

As mentioned by Tim Seguine do not use onkeyup, instead use addEventListener and attachEvent if you need to support older IE versions. Furthermore : chkPasswordStrength(txtpass,strenghtMsg,errorMsg) ...

View answer
Simple Async Google Maps initializer with AngularJS
Accepted answer
13 votes

I like it, you could clean up the commented out code and possibly replace $window.googleMapsInitialized = function () { mapsDefer.resolve(); }; with $window....

View answer
JavaScript/ECMAscript 6 classes organization
Accepted answer
13 votes

Most interesting, In BaseObject, you should really have a constructor that builds this.listeners, it would make your code much cleaner afterwards I am not sure why your listeners are not private in ...

View answer
Code indentation for declaring inputs/outputs in an array
12 votes

An opinion question, always tricky. From a DRY perspective, your code should be usable to generate documentation, like 'what use cases does this routine support' or 'What are the mapping values ...

View answer
HTML Editor: online HTML editor with real-time preview
11 votes

In all, quite impressive code, here are some pointers: Besides the suggestion to compare with 0 via ===, JsHint could not find anything Consider using addEventListener instead of the old skool onxxx ...

View answer
Tape Equilibrium
11 votes

From a once over, you seem to call sumofArray a number of times, you should only have to call it once. At the very beginning, you call it once for the entire array, results should be 13 Then for ...

View answer
Rotating array members
11 votes

You should use shift and push function rotate( array , times ){ while( times-- ){ var temp = array.shift(); array.push( temp ) } } //Test var players = ['Bob','John','Mack','Malachi']; ...

View answer
"Do I understand the gravity of the situation?"
10 votes

I spent quite some time looking at this: High Level I love what you did here, a great showcase of using JavaScript in a powerful way. But from a readability and maintainability perspective, this ...

View answer
Find a nested property in an object
Accepted answer
10 votes

From a once over: Be careful for js structure with cycles (like nodes in the DOM), you will get into an infinite loop. This will also not find dupes, that may or may not be a problem You also want to ...

View answer
Human anatomy quiz
10 votes

From a once over: You have the question and answer as a string, I would store the answer as a number: { "question": "What is function of respiratory system?", "choices": ["help u gain nutrients",...

View answer
Finding longest word in a string
10 votes

Just wanted to point out that @200_success's review is excellent, but personally I would go for reduce: function longestWord2(str){ var words = str.replace(/[^A-Za-z\s]/g, "").split(" ...

View answer
Draggable Resizeable Box
Accepted answer
10 votes

From a once over: It makes more sense from a UX experience to create the box on click then on mousedown There are a number of indenting inconsistencies, use TidyUp in jsFiddle to fix that Naming is ...

View answer
Ultimate Tic-Tac-Toe Challenge
10 votes

From a once over: I would use the HTML 5 tags, they are cleaner and more appropriate: <!DOCTYPE html> <html> Your code validates perfectly as HTML5 The UI setup probably deserves ...

View answer
Fastest way to cut an array into two arrays at a particular index
Accepted answer
10 votes

I am pretty sure you can use copyOfRange(double[] original, int from, int to) from java.util.Arrays. @Rolfl said, and I quote : It is recommended practice to use Arrays.copyOf instead of System....

View answer
Advice needed for scopes in JavaScript
Accepted answer
10 votes

How can I not mess up the global scope? You can use an IIFE ( Immediately Invoked Function Expression ) to surround your code and then assign all your variables with var <- Very important. (...

View answer
A more readable InStr: StringContains
Accepted answer
10 votes

My 2 cents, the first function seems fine, you could make it a little DRYer by just setting the compareMethod in your if statement and then have only 1 complicated line of logic. And if you are doing ...

View answer
Snake game with canvas element code
Accepted answer
9 votes

From a once over: Good I like how you use an IIFE I really like how you use direction = keys[event.keyCode]; Not so good You are not consistently applying the 2nd good technique, for example this: ...

View answer
Mapping Yahoo weather codes to CSS classes
Accepted answer
9 votes

If you don't mind using the 'JSON strings as index' trick, you can do the following: var classMap = { '["basecloud", "wind"]' : [0,19,23,24], '["basecloud", "rain"]' : [1,2], '["basecloud", "...

View answer
Simplifying constructing native SQL query with nested if-else's
8 votes

A very short review; Escape your parameters with escapeSql, this is so important! You should pass the conditions in array, so that the call can pass an arbitrary amount of conditions ...

View answer
Making lines with SVG and JavaScript
Accepted answer
8 votes

Let me know what I can improve on or what I'm doing poorly. If you are going to do animations with those lines, you will want to keep track of them. I am assuming that is why you have an array of ...

View answer
AngularJS Todo List - too much controller logic?
Accepted answer
8 votes

This is a funny question because One of the most readable Angular submissions on CR There is probably too much logic in the controller indeed Some observations: It seems the controller knows too ...

View answer
Determining if a check box has been checked or not
Accepted answer
8 votes

A common question, your question is not so much ugly as it is repetitive. Because of that it violate DRY. You basically have copy pasted the same structure over and over : if ($("#XXXOld").is(":...

View answer
Nested Sets in JavaScript
8 votes

Interesting code, the first thing that comes to mind is that forEachand map are slower than for loops, so you might want to consider converting those statements to for loops. the second thing is ...

View answer
1
2 3 4 5
27