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] ... ]...

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...

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...

I've created a site for an artist friend of mine, and she wants the layout to stay the same, but she also wants new paintings she'd produced to be mixed into the current layout. So I have 12 thumbnails (thumb1 - thumb12) on the main gallery...

Yesterday I was looking to check if a point was inside a polygon and found this great script: https://github.com/tparkin/Google-Maps-Point-in-Polygon But today at work I was told that our client needs to check if one polygon is inside another polygo...

It must be noted here that I performed the mathematics by hand on paper to derive the foregoing proofs. I am not sure if the proofs would have become apparent by solely using the medium of the modern computer. The definition of "efficiency"...

©2020 All rights reserved.