What is the most concise and efficient way to find out if a JavaScript array contains a value?  This is the only way I know to do it:  function contains(a, obj) {     for (var i = 0; i < a.length; i++) {         if (a[i] === obj) {             r...
I have a simple JavaScript Array object containing a few numbers.  [267, 306, 108]   Is there a function that would find the largest number in this array?...
I need the fastest way to get the first day of the week. For example: today is the 11th of November, and a Thursday; and I want the first day of this week, which is the 8th of November, and a Monday. I need the fastest method for MongoDB map functi...
How would you implement the Cartesian product of multiple arrays in JavaScript?  As an example,  cartesian([1, 2], [10, 20], [100, 200, 300])    should return  [   [1, 10, 100],   [1, 10, 200],   [1, 10, 300],   [2, 10, 100],   [2, 10, 200]   ... ]...
I am working on an isometric game engine and have already created an algorithm for pixel perfect click detection. Visit the project and notice that click detection is able to detect which edge of the tile was clicked. It is also checks the y-index...
Code in question with syntax highlighting here: via Friendpaste  rot13.js:     ERRONEOUS  <script> String.prototype.rot13 = rot13 = function(s)  {     return (s = (s) ? s : this).split('').map(function(_)      {         if (!_.match(/...
I've seen versions of this question for other languages, but not for JS.  Is it possible to do this recursively in one function?  I understand that I need to take the first element in the string, and then append it to each solution to the recur...
Requirement: Algorithm to generate all possible combinations of a set , without duplicates , or recursively calling function to return results.  The majority , if not all of the Answers provided at Permutations in JavaScript? recursively call a fun...
I was trying to pack circles of different sizes into a rectangular container, not packing in circular container that d3.js bundled with, under d3.layout.pack.  here's the layout I want to achieve:    I've found this paper on this matter, bu...
I have a set of metallic sliding pieces which are constrained to the x and y axis in following way:    I would need to maximize the horizontal distance among all pieces constrained by the same slider and the vertical distance among the sliding piec...

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.