Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

3
votes
1answer
65 views

Multi-field sorting

A function to sort data on multiple fields. I welcome feedback. ...
8
votes
1answer
207 views

Cookie Clicker Switches

In Cookie Clicker there are Golden cookies, and Wrath Golden Cookies. Golden cookies are Clickable cookies that randomly appear, and when clicked they give Bonus cookies, or temporary boosts to ...
2
votes
1answer
132 views

Sorting elements in array with a certain condition

This is what I have: function get_create returns a link with new filtered/sorted properties: Code on screenshot ...
1
vote
0answers
157 views

WebSocket based API library in Julia

I made a very bare-bones API "library" in Julia which should abstract the interaction with the API. The API is fairly complex - it's based around 2 core layers an HTTPS/REST API for general ...
0
votes
2answers
68 views

JavaScript recursive zip function

Could the performance of this function be optimized (without making the code much longer)? The function zips two arrays into another. ...
5
votes
1answer
134 views

First all zero row of a matrix in C++

The problem of finding the first all zero row in a NxN matrix was featured in a letter to the CACM in 1974 by Frank Rubin who claimed it was a problem for which using a ...
4
votes
2answers
829 views

Wrath Cookie Switch for Auto Golden Cookie Clicker

Sometimes you feel like a wrath cookie and sometimes you don't. Here is a function that I created that will run on an interval, so all I have to do is set a boolean when I want to switch between ...
0
votes
1answer
131 views

Conway's Game of Life in JavaScript sprawling iterative function

I'm new to JS, React and functional programming and am trying to make the Game of Life in React. My cycle function looks like iterative sprawl but all my attempts to refactor have been equally bad. ...
1
vote
1answer
44 views

Implement 'Foldable' on NonEmpty

Given: data NonEmpty a = NonEmpty a (Array a) I completed the following exercise from PureScript by Example: Write a Foldable instance for NonEmpty. Hint: ...
6
votes
1answer
853 views

Function composition in Python3

I wanted to implement a version of rambda's compose function in python. I also implemented some examples to show its working. However, I would like the community's input on my code: These are the ...
1
vote
0answers
44 views

Creating and manipulating a map for a text based game F#

I have put my whole code so far below, but what I am most interested in is how best to implement the map and utilise it. Any tips on organising my code and keeping it clean would also be greatly ...
1
vote
1answer
280 views

Vert.x application quickstart

I have created this repository that implements this OAuth2 flow. I wanted to use Java and create a minimal implementation of this flow with these goals in mind: Develop unit and integration tests in ...
1
vote
2answers
113 views

Reducing array to average readings

Taking the payload below, I need to output the average of each reading. For example the readings for key 2 are 1, 4, 7. The average is (1+4+7)/3 = 4. The data is formatted in multi-dimensional ...
6
votes
1answer
2k 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 ...
0
votes
1answer
4k views

Getting the grandparent directory of the current code [closed]

I have this example: from os.path import dirname, realpath dirname(dirname(dirname(realpath(__file__))) And the chained ...
1
vote
0answers
47 views
1
vote
1answer
238 views

Take a number and sum its digits raised to the consecutive powers

I am new to Scala have to solve this problem: If you have number "xy" should equal sum of consecutive powers of its digits xy = x^1 + y^2 For example, take the number 89 and you should ...
1
vote
0answers
51 views

Custom indexeddb modules while trying to maintain the functional paradigm as much as possible

I'm a Web Development student, and I just started learning indexeddb a little while ago. At present my teacher hasn't taught us Promises, and I'm not really sure he plans to. So, I took the initiative ...
3
votes
1answer
205 views

Sorting a list of phone numbers by teleconference provider and location

I'm looking to order an array of phone numbers with a primary sorting criteria of whether the teleconference provider is correct and a secondary criteria of whether the the location of the phone ...
5
votes
3answers
64 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 ...
0
votes
3answers
276 views

Binary search algorithm in Clojure

I'm absolutely new to Clojure (started learning it yesterday). After I went through some tutorials and checked out the basics I implemented the following Binary search algorithm: ...
1
vote
1answer
64 views

Functional Implementation of Co-prime pairs in array

Program finds the number of pairs of co-primes in an array using functional concepts in Node.js ...
5
votes
2answers
195 views

General FizzBuzz in Scala

I wanted to create a FizzBuzz implementation that both showcases the strengths of Scala (Functional paradigm and collections) and is general enough to anticipate the typical interview follow-up ...
3
votes
1answer
157 views

Find an unknown length using sohcahtoa (Trigonometry)

Here is a calculator for an unknown side in a right-angle. Is there a more efficient way of doing this? ...
8
votes
3answers
587 views
0
votes
2answers
134 views

Reduce a JavaScript array into named objects

The code below reduces an array into "named" objects (not sure if that's the correct terminology!) It works, but I'm sure the code could be improved. There is some repetition going on in the reduce. ...
1
vote
0answers
90 views

Folktale 2 skeleton workflow for resetting a forgotten password

I am learning more about functional programming via loop recur's online book Mostly Adequate Guide to Functional Programming, and Brian Londorf's video series on egg head. I started using ...
1
vote
2answers
85 views
4
votes
1answer
45 views

Implement clojure-a-like comp() function in python3

With a friend some time ago we wanted to write our own implementation of comp() clojure function in python3. we ended up writing the following function: ...
2
votes
1answer
330 views

First-class objects in Python

As a beginner, in order to cement my knowledge of functions in Python, I’ve prepared this Jupyter notebook First-Class Functions. The code in it is working, but before moving on to closures and ...
2
votes
1answer
81 views

Project Euler 23 in Scala (non-abundant sums)

I recently overhauled my solution to Project Euler Problem 23 (which asks for the sum of all positive integers which cannot be written as the sum of two abundant numbers) to move it from an imperative ...
1
vote
2answers
62 views

Getting a string from a range of possible paths

I have a scenario where I need to grab the first occurrence of a string from an object, but only if the match occurs in one of the path's that have been pre-defined. ...
0
votes
1answer
63 views

Report a status based on a list of results

In one of my services, I have the function as presented below: ...
4
votes
0answers
81 views

Simple wrapper function grouping and summarising variable

Background I've wrote a trivial wrapper function summarising variable by group for dplyr. I would like to handle quosures more efficiently. In particular, I've a hunch that ...
2
votes
0answers
75 views

React - Higher Order Component

My first go at a Higher Order Component in react. Aims to give a component the ability to call an url repeatedly with a given refresh interval. Seems to be working as I want. I'm not 100% confident ...
2
votes
2answers
51 views

Grab the first 4 items that meet the condition from a data set with an unknown size

I was turned down for a job after a coding take-home test, and some of the feedback I received was: would have preferred to see more functional programming instead of while loops - and the while ...
0
votes
1answer
73 views

Promisifying a third-party JS library with minimal code overhead

Context and Existing Code I am trying to "promisify" a third-party authentication library (auth0-js) written in JavaScript. Right now it uses callback functions and there are no plans to expose an <...
3
votes
3answers
451 views

Array flatten with recursion

I'd been using this form for a while now with the functional methods map, filter, reduce: ...
2
votes
1answer
62 views

Clean up string and move the noun before the comma

I would like to know how I could improve the regex part of this script? I now chain 4 replace methods which is not optimal. Any ideas of other improvement I'm happy to receive. ...
7
votes
1answer
610 views

takeWhile, groupBy and group higher order functions

I'm trying to implement few higher order functions from Haskell in C++. Below are the definitions of takeWhile, groupBy, and <...
-1
votes
2answers
81 views

javascript reduce list of a multi attribute list of objects on one key but returning more than one attribute

Is there a better way to do this? I have a list of objects. I want the list has two values: an ID and a NAME. Both Name & ID are distinct taken separately of together. ...
3
votes
1answer
135 views

Grab first successful pair from a list of maps

I have a function that parses geographic coordinates through a list of different providers. In this case I want to look up two addresses. The main problem of this question is - given a List of of ...
3
votes
2answers
294 views

Splice from Array if index matches

This code loops through an array called $rootScope.watchlist (uses AngularJS). It gets the current iteration of the loop to access that x iteration through ...
2
votes
1answer
60 views

Building objects in javascript, without “if(!a[k]) a[k] = []”

When building objects using reduce, I often have crappy code like this: ...
1
vote
1answer
259 views

Control class for an entity

For a Student object in the package entity, I have a control.studentpackage with classes ...
6
votes
2answers
622 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 ...
7
votes
1answer
240 views

Functional K-way merge (Merge k sorted sequences)

I've implemented a functional k way-merge algorithm to merge k sorted sequences of any type T. I used scalaz's Heap since the Scala standard library does not provide an immutable heap. Any suggestions ...
2
votes
0answers
153 views

Groovy Map/Reduce for Jenkins DSL

Jenkins DSL doesn't support collect and inject from what I can tell (I get missing method exceptions when I try), so I ...
4
votes
3answers
350 views

Counting votes for candidates in a category and region

With the following code, I want to count the Vote objects from a collection, filtering on one of their fields, Candidate. I have the feeling that I can get this done much more efficiently. ...