Questions tagged [underscore.js]
Underscore is a library for JavaScript that provides functional programming support.
51 questions
0
votes
1
answer
78
views
Deep custom AngularJS Filter
I need to filter projects using a searchbar, it should filter all properties of the projects with a few exceptions. It's working, but it's extremely slow, where can I make optimizations?
The "_" is ...
5
votes
5
answers
17k
views
Optimizing a nested for loop over JS array of objects
NOTE: I'm bringing this question up in code review rather than stack overflow since I already have a working solution. I just am looking for ways to do it better.
I have two arrays. One is an array of ...
4
votes
1
answer
2k
views
My first animated data grid with Vue.js
Because this is my very first attempt to create a data grid with Vue, I would like to know about all misconceptions used in my approach. Whomever points to the most important shortcoming / weakness in ...
2
votes
0
answers
162
views
4
votes
1
answer
120
views
Convert object with 'long.property.name' property to object tree
I want to transform such object from:
foo = {
42: 'foo',
'a.b.c[0].42': 'bar',
'a.b.c[0].43': 'zet',
'a.d.c[0].42': 'baz'
}
To:
...
3
votes
0
answers
476
views
Two reimplementations of the Underscore _.reduce function
I am working on rewriting the underlying code for some Underscore.js functions. Re-writing the reduce function has been causing a lot of headaches. I have been able to re-write it two different ways, ...
2
votes
1
answer
292
views
Shipping calculator consisting of one field
A made a shipping calculator, which consists of one field that is validated.
jsFiddle
HTML:
...
1
vote
1
answer
214
views
Retrieve unique child objects from an array
I'm using TypeScript but this example is in plain JavaScript. I have a class rank with a child-class master. I need an ordered ...
1
vote
1
answer
669
views
Characters set permutations with repetitions
The code bellow generates all the permutation(with repetitions) for given character set. Is there any better(simpler, more performant) way to do that?
...
1
vote
1
answer
163
views
Grouping an array by postId and userId
I've got this kind of data:
[
{ userId: 1, postId: 1, ... },
{ userId: 1, postId: 2, ... },
{ userId: 2, postId: 3, ... },
...
]
And I need to group them ...
1
vote
1
answer
232
views
jQuery calendar plugin (using underscore templates)
I put together a jQuery plugin that displays a month of dates using underscore templates. When the template has been populated and displayed in the UI, a user can click on a date which sends a request ...
4
votes
0
answers
109
views
Backbone learning piece, Movie Application using Views, Collection, Models, Routes and Localstorage
I have created a Backbone Movie app as part of a learning exercise, the app is hosted on codepen although I actually have it built on my local but thought this approach would be handier for code ...
4
votes
3
answers
172
views
Genetic Drift Simulator - Follow Up
This question is a follow-up of a previous question of mine: Genetic Drift Simulator.
Following the advice given in the last question, and some more general improvements, the code has been slimmed ...
7
votes
1
answer
47k
views
Merging two arrays of objects with different keys/properties [closed]
I have two different arrays:
...
3
votes
1
answer
13k
views
Aggregate sum by month
I have JSON data:
var data = [ { dat: 'timestamp', val: 10 }, { dat: 'timestamp', val: 20}, (...)]
Data contains objects with timestamp and value, can be more ...
2
votes
0
answers
79
views
Extremely redundant HTML templating
This is horrendous.
I'm using lodash's templating engine for this table. Here's the template for an individual record's row. I've got 5 different table and ...
4
votes
1
answer
169
views
Making my underscore template code more manageable
I currently have what seems to be a very overly complicated underscore template full of conditionals and as the data grows I'm worried the conditions are going to get more and more extreme. Can anyone ...
3
votes
1
answer
590
views
Looping through nested arrays with creating new array from nested items
I have written this function but I am not so proud on it. I could use some help refactoring it.
Would recursion improve my code?
Data sample.
...
2
votes
2
answers
449
views
Model object for form validation
In order to perform form validation, I have created a custom object:
...
1
vote
3
answers
11k
views
Sorting object with null values underscore sortBy
I'm sorting my object by its property ActivityOrder, which will sometimes contain null values if the user has not explicitly ...
2
votes
1
answer
934
views
Reimplementation of Underscore _.throttle
I've built a function that mimics _.throttle (returns a new, throttled version of the passed function, that, when invoked repeatedly, will only actually call the original function at most once per ...
11
votes
1
answer
2k
views
Martian Robots - a small JS program
Please look at a small piece of code I wrote and provide some thoughts, critiques and any feedback you think is needed.
The code is here along with the problem I have attempted to solve and I look ...
3
votes
1
answer
809
views
Underscore.js and jQuery templating
I want to improve my code or structure. How does it look? Any comments or suggestions?
...
0
votes
1
answer
106
views
Functional implementation of collecting objects into groups
Trying to write more functional Javascript with the underscore library. Any thoughts on how to improve this to be more functional than imperative? Also, any way to do this without ...
7
votes
2
answers
5k
views
"Invert" a JavaScript object hash whose values are arrays to produce a new object hash with keys as the elements of those original value vectors
Background
lodash and underscore have an invert function that takes an object hash and converts it to a new one, which has keys as the input object's values and ...
6
votes
1
answer
4k
views
Adding ranks to objects in an array
This works, and I personally find it elegant and kind of "neat," but then I worry it's a bit too tricky. Comments welcome:
...
4
votes
1
answer
155
views
UI for adding roles and modules to a user list
I have a small UI that involves adding roles and modules to a user database array. The interface works as is, no problem at all, but it seems to have a bit of 'duplicate' code that I was hoping I ...
2
votes
1
answer
120
views
Adding HTML DOM template
I'm new to JS and jQuery. I wrote this function which just does what I want, but it seems very unreadable, and because of my experience, I don't know a better way to handle it.
Could you please give ...
2
votes
0
answers
131
views
Bitcoin, detecting deposits to the node.js server
I'm trying to detect deposits that a user will make. I added explainatory comments inline.
Can you spot any flaws in it?
...
7
votes
1
answer
22k
views
Converting an object to an array of objects
I've written a method that takes an object whose keys are arrays and converts it to an array of objects.
I feel like the code is fairly complex, after waiting a week or so and revisiting it, I don't ...
2
votes
1
answer
217
views
Making empty cells in Underscore template
From the back-end, I am receiving 8 data. The client requires showing that the row per data is 7, so I have 1 data in balance. I have created empty data and made the empty cells, which works fine. But ...
4
votes
1
answer
284
views
Utility library and Underscore mixin - 1
This code is similar to Underscore. I've added in some functions to fill in different use cases.
For example, one can use someKey to iterate through ...
2
votes
1
answer
6k
views
Underscore template conditional can be reduced
I have 11 data items and would like to print them as a group. Each group will have header and at the end of the group I need to print continue label.
For that, I ...
0
votes
1
answer
123
views
Function with underscore overuse
The code below is converting: data from one format to another
...
6
votes
1
answer
2k
views
Simple JavaScript Backbone.Js tool to highlight multiple search terms
I wrote a simple JavaScript tool to highlight multiple keywords at the same time in some text. It uses different color for each keyword, and also shows the count of matches.
I'm using Backbone.js ...
8
votes
1
answer
317
views
Interactive API documentation page of a RESTful dictionary API using Backbone.js
I'm working on the interactive API documentation of a RESTful dictionary service.
The page should let testers try the different API calls,
by playing with the parameters using a simple web form.
...
19
votes
2
answers
80k
views
Deep pick using lodash/underscore
Use Case
_.pick creates a shallow clone of an object given a predicate that identifies which keys to keep. pickDeep would ...
0
votes
2
answers
113
views
Is there a simple way to use Underscorejs to achieve this?
I have an object, having key and values. I'd like to pick the object and call the appropriate function from the key:
...
2
votes
3
answers
24k
views
Get the Key of the highest Value in JavaScript object [closed]
Given a hashmap (or a "Dictionary") as a JavaScript object, I'd like to get the Key who has the maximum Value - assuming all Values are integers.
In case there's more than one, I don't care which one ...
6
votes
1
answer
148
views
Seven days a week
I use the jQuery Calendar with an underscore template and I wanted to put <li> tags around each week. This does the trick, but it's awful.
...
5
votes
2
answers
3k
views
Adding a bulk of items in the middle of a sparse array
I'd like to add a bulk of items into a sparse array, starting at a certain index.
I came along this requirement in order to accomplish client side pagination while not retrieving all data from server (...
2
votes
2
answers
8k
views
How to sort two array of objects using Underscore.js? [closed]
I am sorting 2 arrays of object like this, but I know this is very bad. Any good approach, like using each method like so? ( I tried, but using each, I am unable to return the object )
...
0
votes
2
answers
211
views
Utility package comparable to underscores.js
Compare to underscorejs if it pleases you. Once again, I hope this is well commented. Please let me know what comments/improvements I can add.
Please review all aspects of this code.
...
2
votes
1
answer
353
views
Need review and best practice tips for a Backbone project
I made a simple app that fetches the favourite programming language of a Github user, by simply inserting their username. The full code is uploaded on Github, please feel free to fork it from https://...
12
votes
1
answer
784
views
Unordered list element via templating
I'm creating an unordered list element in Backbone via Underscore templating:
...
2
votes
1
answer
182
views
Validator function in Backbone
I have inside a Backbone model validate function several if statements:
...
5
votes
2
answers
9k
views
Recursively walking a tree to build up a new one
Could this be better factored as a reduce?
...
1
vote
2
answers
197
views
2
votes
2
answers
3k
views
Date formatter for javascript
I just coded this formatter to format timestamps in javascript (I tied it to underscore for convenience), any remark?
...
1
vote
1
answer
135
views
Underscore and general app design review
I'm working on my larger project to date, and on top of that I'm using underscore for the first time.
All is working perfectly but I'd like some criticism on the use of underscore templating and ...