Questions tagged [comparative-review]

This tag is used for questions which present a problem and multiple solutions, where the asker wishes to know which solution is best (and why).

Filter by
Sorted by
Tagged with
2
votes
2answers
84 views

How can I optimize this pairwise Euclidean distance search algorithm?

x and y are two-dimensional arrays with dimensions (AxN) and (BxN), i.e. they have the same number of columns. I need to get a matrix of Euclidean distances between each pair of rows from x and y. I ...
1
vote
0answers
39 views

Higher-order function to do throttling, written two ways

I have used below method for throttling which is a Higher Order Function (HOF), but find some difficulties to choose which one is better way to write it. Below are both methods. return of the ...
0
votes
0answers
50 views

Multiple flatMap style: Nested or sequential?

This question applies to any language with flatMap -- e.g. functional languages -- but I'll use an example in JavaScript. I'm working my way through Functional Programming in JavaScript, which is a ...
0
votes
3answers
191 views

C# 'out' keyword in JavaScript [closed]

Since I met the out keyword in C#, I'm trying to find an equivalent in JS. So, please take a look at the code and leave your opinions or suggestions about this. C# ...
0
votes
2answers
64 views

List of objects inside same model vs Factory vs Service [closed]

I am creating a simple Country class. This Country have list of know countries. we can get the list of known countries Country.AllCountries, ...
-1
votes
3answers
79 views

Populate a color table in XCB

This function has 16 repeated calls to the same function, passing in the same handles to each: ...
0
votes
1answer
52 views

Convert string to 10 character string with leading zeros if necessary

I have the below data and am obtaining the expected output column for it. ...
1
vote
2answers
56 views

Comparison of 2 different ways of writing Merge Sort Algorithm

I have recently learned Merge Sort algorithm in C++ with 2 ways of writing it. 1st Way: ...
2
votes
3answers
72 views

URL & HTML encodings on pagination

I wrote this Pagination Section. It shows links to pages 123456789 and so on on SERP (Keyword Search Result Pages). Like you see on Google SERPs. Even though they work, I'm not sure I finished them to ...
5
votes
5answers
653 views

Comparing 2 distinct sieve of Eratosthenes algorithms in Java

In this post, I will present and compare two distinct algorithms for sieve of Eratosthenes: com.github.coderodde.math.prime.PrimeFinder ...
3
votes
3answers
112 views

Comparing 8 different Disjoint-Set data structure variants in Java

The Wikipedia page on Disjoint-Set data structures presents \$4\$ distinct algorithms for finding the root node of the tree, and \$2\$ distinct algorithms for performing the union operation. In this ...
1
vote
0answers
36 views

Graph stored as adjacency list or as endpoints and intervals

I tried speeding up my Graph class, so I removed the Node class and Edge class, and decided to use arrays and ArrayLists. My 2 implementations seem very similar, ...
1
vote
2answers
98 views

Search for text in a file

I have this implementation of Grep where I use re.search: ...
0
votes
0answers
29 views

Chain the same Runnable using Handler in Android

Which approach to creating repeating Runnables is better? ...
1
vote
1answer
83 views

Which of these two Vuetify Navigation Drawer prevent prop mutation workarounds seem better?

I am very new to Vue.js, I just stumbled on a very hard thing to do (at least for me) where Vue was complaining about mutating a prop (children shouldn't change parent props apparently). I was about ...
0
votes
3answers
77 views

Get the Most frequent element in an array

I have been trying to optimize this: ...
2
votes
2answers
113 views

Counting uppercase and lowercase characters in a string

I created two programs (one with JAVA8) to calculate the total count of uppercase and lowercase characters in given String. After checking the execution time JAVA8 is taking longer execution time than ...
3
votes
2answers
227 views

Parsing custom text file using haskell

I am working on writing code for find difference between two text files that should be ideally same. the format of file is ...
3
votes
1answer
63 views

Posts data to endpoint, trying not to use .Result on async methods

I have a Send method that is working but want to refactor a portion where it is using PostAsync().Result and ReadAsStringAsync().Result. I've never written async methods before and don't feel I ...
2
votes
1answer
75 views

Dose tracker with daily and weekly totals

This is an old script I made a while ago. What it does It tracks your dose of whatever you want tracked (cigarettes, salt, etc), outputs the total for each day, and the full week. What I’m looking for ...
3
votes
1answer
99 views

Find the largest decrease in a sequence of numbers

I have written a function that takes as input a list of 5 numbers, then the program's goal is to return the largest drop in the list. It is important to understand that [5, 3, ...] is a decrease of 2 ...
3
votes
1answer
52 views

Using Numba works slower than not using it for my Python code

I thought this community is better place to ask my question so I ask here rather than at StackOverflow. Recently, I learned that Numba can make Python function ...
5
votes
2answers
261 views

Spliting Greeter class to multiple small classes

Write a Greeter class with greet function that receives a name as input and outputs ...
3
votes
0answers
44 views

class uploade file(photo,video,..) laravel

I am working on a project, the previous programmer used this method to save photos, videos, etc. ...
5
votes
1answer
115 views

Copy Columns Forward Macro: From Procedural to OOP

Background: I had created a macro few years ago and when I was reviewing this now, it was hard to understand. I recently went through all the articles from ...
1
vote
2answers
238 views

URLify a given String - replace spaces with %20

I have written a code to replace all spaces in a String with %20. ...
2
votes
1answer
50 views

Which solution of the two is the most efficient? Is there a better one? (IP Address Defang)

I just started doing preparation for interviews, but im having trouble recognizing the optimal solution Problem: For a given IP Address, replace every "." with "[.]" Example: ...
1
vote
1answer
62 views

How can I refactor for handling multiple proto generated service clients by eliminating double await and the DRY code?

I'm having doubts about which is the best strategy to manage the many service clients in this web app. "Best" in terms of a good compromise between user's device RAM and Javascript execution ...
1
vote
1answer
50 views

Changing an element in a list when a predicate holds

My current project is a Settlers of Catan server in Haskell. I often manage to achieve my goals within Haskell, but the code is getting messier as the project grows. My question is about the ...
1
vote
0answers
37 views

Asking for feedback, when utilizing Pandas, why is it better to use pandas.Series than lists data type?

I found out the hard way, when utilizing pandas is better to use pandas.Series than lists data type to manipulate data. Even if ...
2
votes
3answers
86 views

Sort an array of integers with a hashset

I was trying to make a sorting algorithm for an array of integers. Here's are the steps/theory: It turns an array into a HashSet, iterates over every integer value ...
0
votes
1answer
67 views

need some guidance for better coding practice [closed]

Given a int optimumMemory and int[] array with list of available memories find the pair of indexes of memories whose sum of the values will be equal to the optimumMemory? If there exists more than one ...
1
vote
0answers
30 views

Spectrograph using array-of-slice-references

I've written a working and complete proof of concept that shows a spectrograph in Matplotlib. I want to nail down this proof of concept before I continue with development, and I'm not thrilled with ...
3
votes
2answers
129 views

Debounce function that limits the rate a callback is triggered. Which implementation is better, and why?

The Debounce technique allow us to “group” multiple sequential calls in a single one - The debounce() function forces a function to wait a certain amount of time before running again. I wrote both <...
16
votes
4answers
2k views

Get the first item in a sequence that matches a condition

I've been trying to figure out what's the best, most Pythonic way to get the first element of a sequence that matches a condition. Here are three options: I don't like that I've written ...
2
votes
1answer
331 views

C++: swapping bytes of an uint64_t

This question is about swapping bytes of an uint64_t value, or in other words, about converting between endianness of an integer value: ...
1
vote
1answer
84 views

Perform various actions on a list

I am solving the following HackerRank problem: Consider a list (list = []). You can perform the following commands: insert i e: Insert integer e at position i. <...
2
votes
0answers
37 views

Which of my string indexing functions in Kotlin is semantically closer to my Java one?

I have a working string indexing method in Java and did convert in Kotlin. All methods shown below produce the same result but as I am really new to the Kotlin language I wanted to ask which of my two ...
9
votes
3answers
1k views

Two ways to remove duplicates from a list

The question is - Write a program to remove the duplicates in a list Here's how I did it- ...
1
vote
1answer
55 views

Calculate how many days to add to a process based on destination country or state

I am refactoring a function that calculates how many days to add to a process based on destination country or state. The original function called the database twice, even though the database table ...
3
votes
1answer
37 views

Text centered in a circular component

I have surrounded my initials with a circle. This is intended to be a re-usable component in a responsive layout. (When it is re-used the text will always be two letters, and the font won't change. It ...
5
votes
2answers
232 views

Solution discussion on the best way to reverse a number in Python

I'm practicing some python exercise and I have some doubts about the solution of reversing a number. Example, 42 -> 24, -314 -> -413. The book has this solution: ...
3
votes
1answer
125 views

LeetCode 1115: Print FooBar Alternately

I'm posting two solutions for LeetCode's "Print FooBar Alternately". If you'd like to review, please do. Thank you! Problem Suppose you are given the following code: ...
3
votes
0answers
73 views

React Higher Order Components - export wrapped component or wrap it in parent?

I've been learning about about how to use context, and how to make a higher order component to provide context values through props. So, I've created my HOC to pass down the props, and it looks like ...
4
votes
2answers
2k views

Convert array of u32 to Vec<u8> in Rust

In Rust, I want to take an array of u32 values, convert each to four bytes in big endian, and concatenate them to yield a ...
1
vote
1answer
116 views

LeetCode 863: All Nodes Distance K in Binary Tree

I'm posting two similar solutions for LeetCode's "All Nodes Distance K in Binary Tree". If you'd like to review, please do so. Thank you! Problem We are given a binary tree (with root node <...
0
votes
2answers
180 views

Which is better practice for this if elif… else statement? [closed]

If below piece of code has to be restructured to use but one single if-elif block, which is better? 1. or 2.? A = int(input("Enter an integer(1~30): ")) ...
3
votes
2answers
91 views

Is the following divide and conquer recursive algorithm for the exponentiation more efficient than the iterative one for large numbers?

I have the two following algorithms. My analysis says that both of them are \$\mathcal O(m^24^n)\$ i.e they are equivalent for big numbers (more than 32 bits). Is this right? Note that ...
9
votes
5answers
5k views

Print a word, one character per line, backwards

I have a problem that I solved in 2 different ways and I would like to know which one is better, cleaner and easier to read. Problem: Write a while loop that starts at the last character in the string ...
2
votes
2answers
80 views

Common Unit Testing Code – Follow Up

This question is a follow up question to the Common Unit Testing Code portion of my lexical analyzer questions. My primary concern is the code in the header file and the C source file that implements ...

1
2 3 4 5
18