All Questions
Tagged with javascript algorithm
489 questions
6
votes
3
answers
786
views
Collision detection of two rects with rounded borders
I wrote an algorithm how to detect the collision detection of two rects with rounded borders (the code was written using TypeScript but I tried to name things as clear as possible to code be readable ...
6
votes
1
answer
182
views
Code to generate an array of 364 random special characters with 20 random words broken up throughout
I am trying to recreate a Fallout 4 style terminal hacking game, so I wanted to create code to generate the terminal output (namely, 32 rows with 12 characters each and 20 random words spread out). ...
3
votes
1
answer
91
views
Merge discrete integer intervals
What it does
The code starts with a set of integer intervals, and can add new intervals (possibly by updating existing intervals). Essentially, it is a bit array whose index starts at ...
3
votes
2
answers
158
views
Basic Linked List Implementation in JavaScript
Clarification of Intent
Recursion here is used on purpose for practice - note that iteration is preferred in this case (I'll be more clear about where my intentions are!)
Factory function was also ...
2
votes
3
answers
198
views
Efficiently tagging first and last of each object matching condition
How can I make the code more readable and more efficient? (provided code is O(n²) time, but intuition says it can be pre-processed and done in O(n) time)
Description
it tags the first and last of ...
1
vote
2
answers
116
views
A simple performant factorial function
I am new to algorithm and data structure. After a little introduction to the topic, I have decided to implement a function called calculateFactorial, which takes an integer and calculates its ...
1
vote
1
answer
57
views
Negamax AI for playing Connect Four against Alpha-beta pruning AI in Javascript
The working page is in GitHub.
Introduction
This time, I have two AI bots playing Connect Four against each other. The first AI bot uses Alpha-beta pruning, and the other one uses a Negamax with Alpha-...
4
votes
0
answers
54
views
Connect Four AI vs. AI match in Javascript
This time, I have a Javascript program that runs a Connect Four match between two Alpha-beta pruning based AI bots. (See this page.)
ai-battle.html:
...
2
votes
1
answer
62
views
Combining multiple regexps using the `|` operator and grouping the regexps by their flags
I've implemented a function that creates a multiple regular expressions predicate. The idea behind the predicate is combining regular expressions using the disjunction operator ...
3
votes
2
answers
95
views
Optimizing a Function to Check Pronic Numbers in JavaScript
I've written a function in JavaScript to check whether a given number is a Pronic number. A Pronic number, also known as an oblong number, rectangular number, or ...
2
votes
1
answer
108
views
Move timestamp to the next Monday 10:01 AM [closed]
I've been battling ChatGPT for hours now and can't get satisfied with this simple algorithm in TypeScript. These two (hopefully correct) TypeScript+ReactNative solutions should move the timestamp ...
7
votes
1
answer
232
views
Find the longest "common sequence" in two lists
In short, the algorithm must find the longest sequence that joins together common sequences from two lists (a more formal specification is given in the code's header).
The lists are assumed to contain ...
2
votes
2
answers
75
views
Calculating the sum of all k-sized sub-arrays in an array using sliding window algorithm
I need to calculate the sum of all k-sized sub-arrays in an array using sliding window algorithm. Is that a valid sliding window algorithm? If not, why?
...
3
votes
1
answer
134
views
4
votes
2
answers
341
views
Count matching pairs (modular equality)
Problem
Given an array of natural numbers a. Find the number of such pairs of elements (a_i, a_j), where ...