Skip to main content
The 2025 Developer Survey results are in. Explore insights into technology and tools, careers, community and more. View results.
6 votes

Baseball player statistics controller

Bearing in mind that you claim that you do not to maintain this code anymore1, there are a few suggestions I would have about this code: define functions and accept parameters- that should allow the ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
4 votes

Grab the first 4 items that meet the condition from a data set with an unknown size

So that would mean that very large datasets would increase computation time. You should ask if very large datasets are possible. Because if they're not, clean code takes precedence over what would ...
Jonah's user avatar
  • 4,380
4 votes
Accepted

Returning the results of four $resource calls as a JSON array in AngularJS

Never, and I mean NEVER, manually construct JSON. That's just asking for trouble. Construct the object then use JSON.stringify. FYI, arrays are valid JSON so you ...
Joseph's user avatar
  • 25.3k
3 votes
Accepted

Communication to Child Controller

Having to refer to $scope.$parent is absolutely bad-practice, because dependencies will go up and down and all sorts of ways in your application. It will become a ...
Vadiem Janssens's user avatar
3 votes
Accepted

Particle text directive

There's a few files so I'll focus on a more general code review. Overall it looks good! The code is well structured, readable and your logic is easy to follow. ES6+ You're already using newer ...
Craig Ayre's user avatar
3 votes
Accepted

Move an element up / down an array in Javascript

What you are doing isn't very efficient. First you remove the element from the array, and to close the gap, every single element after it has to move position. Then you insert the element again, and ...
Kruga's user avatar
  • 1,134
2 votes

Unit tests for a single JavaScript function

You can use array.map to create errs instead of creating an array and pushing to it. ...
Joseph's user avatar
  • 25.3k
2 votes

File upload in AngularJS causes browser out of memory error

Marshaling the file contents as a byte array is obviously problematic. Browsers can easily upload files through HTML forms, with ...
200_success's user avatar
2 votes
Accepted

Generating a list of menus with AngularJS

Simple answer, no it's not OK this way, you are totally misusing the angular.js purpose. Anugular.js is a framework in which follows a modular pattern, it was designed by the time web wasn't so rich ...
lenilsondc's user avatar
2 votes

Simple angular app - Shopping website

I noticed that you have a spot for controllers, but then in your directive you declare a function for the Controller Attribute instead of using a controller that you have already at your disposal from ...
Malachi's user avatar
  • 28.9k
2 votes

Splice from Array if index matches

A while back, I went through these exercises about functional programming in JS and since then I strive to use those techniques whenever possible. Bear in mind that functional techniques can lead to ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
2 votes

Grab the first 4 items that meet the condition from a data set with an unknown size

A functional approach to breaking out of a loop is to use Array.some(). It would be different than using .reduce() because the ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
2 votes
Accepted

AngularJS - Making Factory and Controllers DRY

One option is to make the function returned by the factory listDataService accept a parameter for the getbytitle() value: ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
2 votes

Collecting a list of documents from a factory for an AngularJS controller

In addition to what Blindman said, I would recommend avoiding using this in nested scopes , which is always confusing and error prone, by assigning ...
Marc Rohloff's user avatar
  • 3,537
2 votes
Accepted

Collecting a list of documents from a factory for an AngularJS controller

Specify this context I support Blindman67's answer. If arrow functions were not supported by all browsers used (e.g. IE - but then again there is little support ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
2 votes
Accepted

Laravel Single Page Application Using Angular Js

This code seems okay for the most part - I don't see any major flaws with the code, just a few things that I will critique below. Despite being spread across quite a few files, this code seems pretty ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
2 votes
Accepted

Script to load controllers dynamically for AngularJS

Feedback This is an interesting way of loading controllers. I like the application of the promises. It does feel a little weird not to have an ng-app directive but ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
2 votes
Accepted

show/hide components

You can use Bracket Notation to have custom object key by ['text'+variable]. ...
sbk201's user avatar
  • 76
2 votes
Accepted

Create objects corresponding to whichever field has value from among a list of fields

This const int STATUS_BASE = 1; const int STATUS_FIN = 2; const int STATUS_FINI = 3; const int STATUS_WAST = 4; const int STATUS_PRGR = 5; screams for an enum ...
Heslacher's user avatar
  • 50.8k
2 votes
Accepted

Selecting/ Deselecting All from Checkbox

I see what looks like a bug. The x variable (which should probably be renamed to something more informative - maybe user?) is a ...
CertainPerformance's user avatar
1 vote

Traverse and modify a deep object

This looks like a very good fit for JSONPath (initial specification, list of libraries). Of course, if you only have this single code part which has to do traversing/modifying in a JSONPath-like ...
ComFreek's user avatar
  • 761
1 vote

Traverse and modify a deep object

You could move the logic that gets each panel / screen etc into it's own function, and remove some of the indenting, like so: ...
user184994's user avatar
1 vote
Accepted

Managing JS objects while preserving references

Instead of checking each property in the result to see whether it was in the source object, simply delete all of the properties in the destination object and then use ...
Barmar's user avatar
  • 373
1 vote

Splice from Array if index matches

Here's what functional style might look like. Unfortunately, it requires index recalculation, and overall more verbose and complicated, even though it tries to go the ".some()" way. :) I believe it's ...
Igor Soloydenko's user avatar
1 vote

Using chartJS in Angularjs to plot IOT data

Feedback The code appears to make good use of AngularJS and ChartJS, as well as promises. For the function that handles the response, I had to move the line that assigns response.data to $scope....
Sᴀᴍ Onᴇᴌᴀ's user avatar
1 vote
Accepted

Unit tests for a single JavaScript function

I would say that, of course, the first version when you split your tests into granular logical blocks is much better and far more explicit. There is even a practice to have a single assertion per ...
alecxe's user avatar
  • 17.5k
1 vote
Accepted

Tying the enablement of one checkbox to another using AngularJS and jQuery

Is there an obvious cleaner way of doing this [?] Without knowing where the element(s) with class name inklogin exist, it can only be presumed that it exists as a child of the element with ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
1 vote
Accepted

Step by step wizard

You code does seem to work without !important. Here is the plunker demonstrating. To better organize your css you could use SMACSS, BEM, OOCSS or some custom ...
user93's user avatar
  • 181
1 vote

Use counter for ajax loader

You SHOULD consider migrating to Angular (aka Angular2, aka Angular5) from ANgularJS (version 1), as it's not developing and soon won't be supported anymore. I guess nested promises would be much ...
Bohdan Mart's user avatar
1 vote

Getting hex colours from a image

General feedback There are a few ways that some of the loops can be simplified (see below). These may or may not improve the high CPU issue. The code makes some repeated calls to functions with the ...
Sᴀᴍ Onᴇᴌᴀ's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible