Questions tagged [functional-programming]

Functional programming is a paradigm which attempts to solve computational problems by the chained evaluation of functions whose output is determined by their inputs rather than the program state. In this style of programming, side effects and mutable data are deprecated.

Filter by
Sorted by
Tagged with
5
votes
1answer
88 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 ...
9
votes
2answers
636 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
2answers
77 views

Removing OO style coding from Haskell

Having coded in Objected-Oriented style my entire programming career, it's hard to adapt to functional style fully. I implemented a simple Hangman game: ...
3
votes
1answer
40 views

Improvements, TicTacToe in Scala

I've just started my journey into functional programming and tried to implement a TicTacToe game Recursively without State in Scala. What I dislike is the JOptionPane but I don't know if i can solve ...
4
votes
1answer
48 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 ...
1
vote
1answer
68 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. ...
14
votes
2answers
32k views

Flatten dictionary in Python (functional style)

I'm trying to learn how to write functional code with Python and have found some tutorials online. Please note that I know Python is not a promoter for functional programming. I just want to try it ...
0
votes
0answers
37 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 ...
3
votes
1answer
88 views

Hackerrank problem: Climbing the Leaderboard (Java)

I am solving the following Hackerrank problem: Climbing the Leaderboard. The problem statement: Alice is playing an arcade game and wants to climb to the top of the leaderboard and wants to track her ...
6
votes
2answers
100 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
0answers
19 views

Writing an idiomatic task-tracker in Racket

I'm trying to learn Racket. I'm coming from a mostly imperative background, but I do have some casual experience using functional languages like SML and working with lists and recursion for small ...
2
votes
1answer
90 views

C++ algorithm to implement multiple operators in one

I have a class called IntMatrix which has 2 fields: ...
1
vote
3answers
191 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 ...
3
votes
2answers
65 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 ...
-2
votes
1answer
26 views

Node.js ws server: global or local functions? [closed]

I'm working on a Node.js chat app project using the ws library. I have it up and running but I'm still making improvements and adding stuff like authentication, etc....
0
votes
2answers
48 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 ...
1
vote
0answers
21 views

My implementation of Clojure's assoc-in

This is my implementation of Clojure's assoc-in function. I am looking for tips on making it more idiomatic and in general, better. ...
4
votes
1answer
59 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, ...
5
votes
2answers
118 views

Implementing parser combinators in a functional manner

I am just starting on my journey of learning clojure (I have just read to the end of chapter 3 in clojure for the brave and true). So for practice, I wrote some parser combinator functions. I am quite ...
1
vote
1answer
42 views

Basic tic-tac-toe matrix in Haskell

Beginner functional programmer... (but not beginner programmer) Currently, I have the following code: ...
5
votes
2answers
87 views

Bloom Filter in Haskell

I recently implemented a Bloom Filter in Haskell and, although I am not new to functional programming, I am a beginner when it comes to Haskell itself. I'll gladly take any feedback regarding the ...
1
vote
1answer
27 views

Ruby Exercise: Implement your own “#group_by” method

Task: "Implement a method 'gruppiere', in a way that it can be invoked on all enumerable objects (Enumerable). The method receives a block and returns a hash. The items of the enumerable a grouped ...
6
votes
2answers
147 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
2answers
418 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 ...
1
vote
1answer
45 views

Functional Python Script to write a large amount of CSVs to database

I just finished up this script that crawls hundreds of local git repos for csv files and then stores them into a database. I've tried to follow a "functional" paradigm for this script but am kind of ...
2
votes
3answers
86 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
0answers
34 views

Longest Substring Without Repeating Characters in ReasonML/Ocaml

LeetCode Problems 3. Longest substring without repeating characters Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", ...
2
votes
2answers
103 views

Creating a new list using a stream

I have a StudentSchedule class that contains schedules of a student, the student may switch between rooms over time. There's no overlap with the date ranges so if a student stops at 2020-01-01 the ...
7
votes
1answer
221 views

Decorator to cache a function result for some time

I recently played around with a script that got some data from the Google API. As I didn't want to spam requests at the service (and potentially get blocked), I made this decorator, which caches the ...
2
votes
1answer
36 views

Efficient Implementation of functional and Lazy evaluation in C++

I am creating a c++ library implementing Java Functional Programming alike interface. In short, the code will look like this: ...
3
votes
1answer
48 views

Maximum distance between space stations HackerRank

I am just working on Flatland Space Stations problem, and it is not seeming to be a tough question, but my algorithm lags in some aspects, since it solves majority of the test cases but fails for some....
1
vote
1answer
91 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, ...
2
votes
1answer
319 views

Longest Substring Without Repeating Characters in Scala

Question is taken from Leetcode and solution works for their test cases. I do see a scope of improvement and make it more functional (getting rid of vars and mutables data structures). Please suggest ...
12
votes
2answers
411 views

Concatenative PostScript library

As a part of picking up concatenative programming, I decided to implement the common concatenative operations in PostScript. Here is my attempt at implementing some of the words in other concatenative ...
3
votes
2answers
110 views

Leap year check in Java (functional style)

I have done the leap year check on https://exercism.io already in a lot of languages. Today I came back to the exercise in Java and was playing around with some maybe more funny ways to do the check. ...
1
vote
0answers
68 views

Does Subscribe sound as a right name?

So I have a Know Your Customer provider interface like this to estimate risks associated with a customer: ...
1
vote
1answer
73 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
1answer
44 views

Scala: Cumulative String Tokenisation

I'm trying to split an incoming stream of strings into cumulative tokens per line item using a function below, ...
3
votes
4answers
686 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
28 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: ...
2
votes
1answer
25 views

naive bayes sentiment analysis classifier in clojure

attaching my try on implementing simple naive-bayes classifier for sentiment analysis as part of learning clojure and using functional programming on ML algorithms. I tried to invest more time in ...
1
vote
1answer
82 views

Functional Utility in C++ (Curry, Partial Binding and Pipeline)

TLDR I created a curry/partial binding "lib. My request for "code review" is, what possible improvements I need to achieve "release quality", if I wanted to release this as a lib? You can see the ...
3
votes
1answer
94 views

Writing pure functions but have a chain

I'm trying to play around with Godot to learn C# and I was trying to creating pure functions to do the velocity, but I found I was repeating myself. ...
3
votes
1answer
121 views

Write a wrapper to REST API with asyncio

I want understand how to correctly structure a functional asyncio-based program. The code below wraps two external APIs to provide the client a simple ...
1
vote
2answers
82 views

Count Substrings for a binary string

Problem is taken from leet code. Give a string s, count the number of non-empty (contiguous) substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in these substrings ...
21
votes
2answers
4k views

C++ function composition

What is a good way to compose std::function objects in C++? I tried the following, and it seems to work well: ...
1
vote
1answer
134 views

Merge k Sorted Lists

The task is taken from LeetCode Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Example: ...
1
vote
1answer
38 views

Name for mconcat implementation for applicative monoid

I have implemented a function mcollect which is effectively mconcat only for applicative monoids: ...

1
2 3 4 5
18