All Questions
Tagged with functional-programming javascript
275
questions
-1
votes
0answers
27 views
3
votes
1answer
64 views
garbage string remover with array or object input
This is the second time I am writing any practical JavaScript so it is pretty likely that I have messed something up.
I am beginner, so just need a piece of advice before sharing the code: Do I need ...
1
vote
1answer
647 views
Find busiest period in building
The task
You are given a list of data entries that represent entries and exits
of groups of people into a building. An entry looks like this:
{"timestamp": 1526579928, count: 3, "type": "...
2
votes
1answer
50 views
Project Euler 1 using functional programming in JS
So I am once again beating a dead horse, by solving the first Project Euler problem:
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these ...
-1
votes
1answer
70 views
Simplifying and optimising function logic [closed]
I asked the same question on StackOverflow but was told to instead ask here since it was better suited. I have a function that I implemented. It is doing a lot of heavy lifting. I would like to ...
-1
votes
0answers
44 views
What would adding a state accumulator to my simple framework solve/add?
I've created a simple node modules that allows displaying a matrix of characters in the terminal, as well as capturing keypresses.
The purpose of the tool is to make simple games like snake, space ...
4
votes
1answer
60 views
Add result-logging to any function
I'm writing a simple function to transform functions by logging the result before returning it.
The function as written by me:
...
12
votes
5answers
2k views
10
votes
4answers
1k views
Restructuring JSON to create a new JSON where properties are grouped according to similar values
I have a JSON structure in the following example format:
...
0
votes
2answers
51 views
Functional Programming Style in Javascript Picking a Random Item from an Array
I'm trying to understand the Functional Programming Paradigm (or style) implemented with Javascript. There are a few things I have difficulties with. The naming conventions, and dependency injections. ...
7
votes
3answers
201 views
JavaScript OOD: 2048
I wrote a 2048 game in JavaScript with an object-oriented paradigm. The game board is presented with a two-dimensional array and each tile holds an integer.
Here is the implementation:
...
3
votes
3answers
659 views
Given a pivot x, and a list lst, partition the list into three parts
The task:
Given a pivot x, and a list lst, partition the list into three parts.
The first part contains all elements in lst that are less than x The
second part contains all elements in lst ...
4
votes
5answers
1k views
Find index of the nearest larger number of a number
The task:
Given an array of numbers and an index i, return the index of the
nearest larger number of the number at index i, where distance is
measured in array indices.
For example, given [...
5
votes
1answer
500 views
Caesar Cipher [The Odin Project-Javascript Exercise]
Very new to coding, so please don't bully me.
Implement the legendary caesar cipher:
In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's code or Caesar shift, ...
2
votes
0answers
29 views
Testing a javascript function that performs side effects
Application context
I am working on a game I call "Apes and Snakes". So far the code only allows players to connect to a host using a room code and WebRTC. Players and the host send messages ...
0
votes
1answer
75 views
JS create array by comparing 2 dictionaries
I have 2 dictionaries that I have to compare, if an element of one dictionary exists in the other dictionary, then add the element to an array but only one time...
here the working code
...
4
votes
2answers
1k views
Return the first word with the greatest number of repeated letters
I'm learning JavaScript and have written a function that accepts a string and returns the first word with the greatest number of repeated letters. For example:
Input:"Hello apple pie" - Output:"Hello"...
2
votes
3answers
410 views
Find nearest k points from the central point
The task:
Given a list of points, a central point, and an integer k, find the
nearest k points from the central point.
For example, given the list of points [(0, 0), (5, 4), (3, 1)], the
...
8
votes
1answer
5k views
“Mars Rover” challenge
I have written the solution of the Mars Rover problem in JavaScript, with a sort of functional approach. I would like to know how I can improve it and if there are any additional edge cases I missed ...
6
votes
3answers
1k views
Counting words from stored .md files
The following searches recursively for all the mark down files - i. ending with the extension .md - inside a folder. It then stores the text of the files in an ...
6
votes
1answer
262 views
Voting app in JavaScript using Ramda
I'm just learning functional programming in JavaScript using Ramda.
I took this tutorial and implemented the server core.js component using Ramda.
The idea is that we'll have a collection of things ...
0
votes
1answer
42 views
Readability vs. maintainability: nested functions [closed]
What are the pros and cons of each option, considering long-term implications (increasing the number of functions / parameters, other developers taking over, etc.)?
Option 1: removes the need to pass <...
3
votes
3answers
378 views
Functional programming FizzBuzz
I tried to code the fizzbuzz program following the functional programming rules in javascript. Please check my code and give feedback. thank you.
...
1
vote
1answer
75 views
3
votes
1answer
144 views
React-Redux with functional Components
This is a pretty simple working example using React-Redux to select a user from app.com/user/:userId and then fetch/display that user's info from a remote API
Most ...
6
votes
4answers
1k views
Convert minutes portion of time to decimal
I am making an hours calculator app. It takes a start time, end time and time taken for lunch.
For the start and end time it takes a four-digit hh:mm time. For example: 10:20.
I have made a function ...
5
votes
3answers
82 views
Aggregate summary counts for an array of error objects
I'm doing some refactoring of someone else's code, and just want a second opinion, because of course I think my work makes it better, but some validation (or correction) would be helpful.
Starting ...
2
votes
2answers
91 views
Cyclomatic Complexity (complexity)
I have a program for finding shortest distance/path and I got a correct answer but I am getting an issue i.e., "Function 'shortestPath' has a complexity of 9. Maximum allowed is 6." This is ...
6
votes
3answers
1k views
await user input with async/await syntax
for clarity: moved here from stackoverflow after being pointed to Code Review being the better place for this question
I love async/await and Promises since I got my hands on them. And I might be ...
2
votes
1answer
131 views
Is the JavaScript code I've provided following Functional Programming best-practices?
I'm trying to wrap my head around JavaScript Functional Programming.
I have created a very basic script that creates a new elements and appends them to the DOM.
If anyone could share any feedback, ...
5
votes
3answers
729 views
Finding even or odd numbers
I'm looking for critiques to see what I could have done better or different ways I could approach writing a script for finding even or odd numbers. I am new to programming with JavaScript, and ...
3
votes
1answer
41 views
Showing values from different fields in an array with ternary
This small piece of code shows the value of different fields of an array.
I'm looking for a way to improve this nested ternary function. An if statement solution ...
5
votes
1answer
84 views
Converting duplicate JS code into a higher order function
I have a block of code that is re-used and I want to use functional programming to remove this duplication.
My code takes an array of items, splits the items into batches of 500 and then does some ...
3
votes
0answers
34 views
Test Driven Development in JS and Sinon Stub
I am going through some TDD and BDD tutorials which guide one through implementing a simple beverage-ordering system. While I think I understand the material, I am still wondering about some ...
4
votes
0answers
93 views
This recursive function encrypts a string
Is there a way to rewrite these last 2 recursive functions with fewer arguments (preferably 2) while keeping them recursive?
The entire code can be seen here: https://github.com/GirkovArpa/hutton-...
5
votes
1answer
83 views
Synchronous logging of asynchronous retrieved folder info
I started learning functional programming with JavaScript and I have the basic idea of Functors, container types and etc. I was trying to experiment with arrays but I don't know how to solve the ...
5
votes
1answer
193 views
Program for calculating and ranking scores
I've recently completed a vanilla JS challenge . It is a method for calculating and ranking scores.
If possible, I would love to make it better. Any suggestions are welcome.
Challenge Directions:
The ...
10
votes
2answers
644 views
Array duplicate removal for duplicates exceeding `N`-number
I recently encountered a front-end interview coding challenge question that required one to create a function which returned an array that excluded numbers that occurred more than ...
5
votes
1answer
69 views
A simple reactjs form to calculate the liquidity ratio, daily cost of running, and days cash on hand
This is just a very simple form that tells you the liquidity ratio, daily cost of running, and days cash on hand of a company, given their current assets, current liabilities, and total expense of the ...
2
votes
1answer
102 views
JavaScript — Convert decimal to another base
The Source code is maintained on GitHub and may be cloned via the following commands. A Live demo is hosted online, thanks to GitHub Pages.
...
1
vote
0answers
43 views
Adding common Python functions to JavaScript
I have written a few classical Python functions in JavaScript. I would appreciate any kind of feedback. The main goal is to learn about JavaScript. For example errors, improvements or existing ...
6
votes
2answers
104 views
Reformatting a structured string like “a-b-c|A-B-C” into “a-A|b-B|c-C”
The code below was inspired by this post in Code Review.
Here is how it was first intended by its author:
I have the following code that converts a string that looks like :
aaa-bbb|ccc-ddd|eee-fff
...
2
votes
3answers
345 views
Functional / Declarative FizzBuzz
I spent some time today trying to write FizzBuzz in a functional/declarative style. I thought it would be a good chance to get some feedback on it since I've been doing functional programming for ...
4
votes
2answers
67 views
Loading items for an eCommerce site
I am attempting to make an eCommerce site from scratch. Right now I have the following code that gets all the items from a Firebase Firestore database and then adds HTML into an items div element ...
1
vote
2answers
51 views
ES6 block-scope variable usage [closed]
I am experimenting with ES6 using BabelJS in a codepen project you can find here. I am confused as to why my code breaks when I decide to use let instead of ...
6
votes
2answers
330 views
Find duplicate in linear time and space
The task:
You are given an array of length n + 1 whose elements belong to the
set {1, 2, ..., n}. By the pigeonhole principle, there must be a
duplicate. Find it in linear time and space.
<...
3
votes
3answers
97 views
Reach to the last index starting at index 0
The task:
Given an integer list where each number represents the number of hops
you can make, determine whether you can reach to the last index
starting at index 0.
For example, ...
1
vote
1answer
81 views
Turning simple Node.JS Postgres query and logging into most-functionally-pure-possible code
After reading "How to deal with dirty side effects in your pure functional JavaScript," I've decided to take something I do on a regular basis ("Original approach" below)—connect to a Postgres ...
3
votes
4answers
2k views
Sum of a sublist
The task:
Given a list of numbers L, implement a method sum(i, j) which returns
the sum from the sublist L[i:j] (including i, excluding j).
For example, given L = [1, 2, 3, 4, 5], sum(1, 3) ...
2
votes
0answers
30 views
Decoding request object before use it in an Insert query
I want to decode a request object before use it in an insert query.
Request object containes the following JSON body:
...