# Tag Info

Accepted

### Extract numbers from a string-Javascript

I used the following regexp to extract numbers from a string: var string = "border-radius:10px 20px 30px 40px"; var numbers = string.match(/\d+/g).map(Number);
• 947
Accepted

### Partitioning an array based on a condition in Javascript

Using TypeScript/ECMAScript 6 syntax it can be achieved this way. I am not sure whether it's more or less elegant compared to the original variant, but It does the job; Requires only one run; Can be ...
• 3,430
Accepted

### Determining whether two scrambled strings are equivalent

This is where the Arrays utility class comes in handy. You can use it to sort the character arrays underlying both strings and then compare the sorted character ...
Accepted

### Zero-initializing large dynamically allocated arrays of double

So my first hunch when I read your question is: Okay this guy is making a complicated solution to a simple problem based on a hunch that the trivial solution is "grossly inefficient" ...
• 16.4k
Accepted

### Duplicate like a weapon, arrays like heaven

@tim suggested a way to do this with less memory by sorting the array. There's another way to do it with less memory without needing to sort. Let's say that $k$ is the duplicate value in the array. ...
• 16.1k
Accepted

### Prime sieve for all primes up to a number

Comments Most people write bad comments. Things that should be commented are idea/decisions/why. Writing comments that explain the code is horrible. This is because comments often fall out of date ...
• 91.8k
Accepted

### Index into array as if it is circular

The arithmetic solution to this is relatively simple as we're talking modulo here: return i % N; This should produce the same results for your adjusted index. ...
• 25.1k

### Partitioning an array based on a condition in Javascript

Anything wrong with the naive ways? ...
• 356
Accepted

### Reverse words in a given String

There are several problems with your approach: It's strange to reverse the letters, reorder the words, and then reverse the letters again. It's inefficient and unnecessary. You could just reverse the ...
• 108k

### Project Euler #1 in PHP

You're using a brute force approach with a linear time complexity in the range and linear in the number of factors i.e. $\mathcal{O}(nk)$ where $n$ is the range of numbers (1000) and $k$ is the ...
• 16.4k

### Finding the majority element in an array

Boyer-Moore for the curious You have a good answer already suggesting the use of a Counter. For simplicity, that's what I would do. However, I had never heard of the Boyer-Moore algorithm for finding ...
• 10.1k
Accepted

### Removing duplicates from an array quickly

You can use the indexOf function to check if a value exists in an array. This would simplify your code greatly: ...
• 108k
Accepted

• 96.8k