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.

learn more… | top users | synonyms (2)

3
votes
0answers
31 views

DRYing a stateless functional builder

This was just an experiment to see if it was possible to build a stateless builder in ES6. I was able to do it, but when I took it a step further I got stuck trying to DRY it out. In this case, we ...
0
votes
1answer
27 views

VBA function that returns color RBG code of a referenced cell [on hold]

I have this function I'm building to return the RBG code of a cell I input. The code "works" but something funny is going on. If I write multiple functions each referencing different cells, then all ...
5
votes
1answer
170 views
+100

Neural Network in Haskell

Following this website I wrote a neural network which uses the MNIST training data to recognize digits. The author writes that it should take a couple of minutes to train the network with 30 epochs of ...
1
vote
0answers
15 views

Generate all permutations in Clojure

Given a set, generate all permutations: (permutations #{1 4 5}) => ((5 4 1) (4 5 1) (5 1 4) (1 5 4) (4 1 5) (1 4 5)) Here's what I cobbled together: ...
4
votes
0answers
31 views

Async.sequence implementation

I have a simple implementation for "Async.sequence" (the name came from here), but I would like someone to review it for performance, tail call optimization, and ...
2
votes
0answers
35 views

Functional Merge Sort

I just finished this Merge Sort in Clojure, structured according to ex. 22-26 of this workshop. The main question I have can be answered without spending time understanding the code: ...
2
votes
0answers
36 views
1
vote
0answers
16 views

React functional components and JS closures to render lists of users

I'm currently working on a project with React and Redux. I try (successfully so far) to write only stateless functional components. My code now starts having a lot of closures, especially when ...
6
votes
3answers
211 views

Use functional-programming to convert a tree of parent:children objects to array

Having some trouble with a code I'm trying to refactor, where I need to go over a 'tree' of items, filter some invalid items, and create a new array of filtered items which takes properties from both ...
1
vote
1answer
61 views

Java 8 functions to avoid try-catch repetition

I'm developing a Java 8 + JSF application, where all the view classes extend from an abstract class called Navegable. All the methods called from the view and ...
6
votes
0answers
103 views

C++ identity function

I've implemented an identity function (well, actually a functor struct) in C++. The goal is that every occurrence of an ...
1
vote
1answer
46 views

String length validation predicate

I partially refactored the code so okFields uses the extracted function checkStringLength. Now I also want problemFields() to ...
9
votes
2answers
203 views

Luhn algorithm in Ruby

I'm learning Ruby 2.3 and I've tried to implement a function which performs the Luhn credit card verification algorithm on an input string, returning true if it ...
9
votes
5answers
252 views

Split IEnumerable by predicate

In order to divide an IEnumerable in C# by a predicate, I implemented the following (in a static class): ...
6
votes
3answers
222 views

Flatten an array

I have got this interview question which has asked me to write a production level code which flattens the arbitrary nested array of arrays. Code ...
0
votes
0answers
35 views

Identifying Types of Triangle in Scala

Below is my solution to this exercise. Write a program that can tell you if a triangle is equilateral, isosceles, or scalene. The program should raise an error if the triangle cannot exist. ...
1
vote
1answer
27 views

Ordering data.frames elegantly by factor

I have a mock_Data: ...
2
votes
1answer
25 views

JavaScript image-Carousel with using IIFE

I have to implement an image-Carousel. Because I'll reuse the snippet within other projects which might contain all kinds of external libraries I used an immediately invoked function expression. ...
6
votes
3answers
514 views

Create an array with the highest values from each array

I am working my way through FreeCodeCamp's Javascript challenges and Return Largest Numbers in Arrays took me a minute. In this one the goal was to create an array with the highest values from each ...
2
votes
1answer
24 views

An interesting use of the reduce function to convert tab-delimited data into JSON

I am learning functional programming in JavaScript. This is some code from a video tutorial by funfunfunction. I am particularly concerned about the way the existence of the customer key is checked in ...
2
votes
2answers
61 views

Custom map on `Array`

I have the following problem: Given an Array, apply a certain method x to each Array ...
4
votes
1answer
64 views

Switch expression function

I made a bunch of functions and an enumeration, that together allow me to write something like a switch expression. It's not as powerful as Swift switch statements, since it's lacking pattern matching ...
3
votes
1answer
42 views

Add functionality to object then remove those functions on export

Outline I have a form that needs validation. The problem is that the software requires custom validation that depends on multiple parameters. I decided to pass the object into a function which will ...
3
votes
1answer
59 views

Create a generator that returns every permutation (unique arrangement) of positive integers up to n

I watched this video from The Unqualified Engineer on YouTube and tried out the challenge. The challenge (or interview question) is to build a generator that returns all the permutations of the ...
9
votes
4answers
131 views

Swap even/odd characters

I wrote some code to solve this problem https://www.hackerrank.com/challenges/string-o-permute which basically states: take an even length string and swap all the even indexed characters. For example ...
1
vote
1answer
34 views

`new Function` for json reference

I have JSON with references to other parts in that JSON file. ...
3
votes
0answers
64 views

childrenCount function in old and functional styles

I'm trying to transition myself from my old coding-style (if-else, for.. in) to functional programming. I've tried to update the ...
1
vote
1answer
75 views

Count the number of vowels and consonants

So I needed to write a function that takes a string and returns a javascript object with vowels and consonants properties that maps to the number of vowels and consonants in the string ...
0
votes
1answer
46 views

JavaScript-function for to convert a dash-separated string into camel case

I have to write a function which turns a string with the words separated by dashes ( - ) into a sentence using camel case notation. I've had the following idea for an implemenation using the reduce-...
1
vote
1answer
41 views

Concat strings from Object or Array

How would you merge these two functions into a single more generic function? ...
0
votes
1answer
30 views

Loading URLs via a case statement

I have the following code which loads in a URL based on the id of a user-clicked button. I'm looking to compress it down as much as possible, and make it more modular and reusable: ...
1
vote
0answers
40 views

Tool for composing functors

What do you think of this code? ...
4
votes
2answers
86 views

Python common file operations generalization

Functions with common and simple file operations have started to repeat in my code. Many like this one, but with subtle differences for example: ...
6
votes
1answer
51 views

Extendable JavaScript module that converts between camelCase, PascalCase, and underscore_case

The basic idea is that by defining the basic functions--recognize, dissect, and combine--...
2
votes
1answer
54 views

Stock performance app

I'm building an app that tells you a stock's percentage change in price between two dates by using Yahoo's API. Given a stock ticker and two dates, it currently outputs the percentage return to the ...
2
votes
2answers
55 views

Determine whether input-output pairs represent something that could be a proper math function

The input is read in line by line from stdin. Input Format The first line contains an integer, T, denoting the number of test cases. The subsequent lines describe T test cases, and the ...
2
votes
1answer
31 views

Read group of keywords from file, modify value, store new group to variable

I would like to use the following routine in my submission script for GAMESS calculations. I am not entirely sure if this is the optimum way to go. This function would need one of the messaging ...
4
votes
1answer
36 views

Checking if input file exists, assign output file destination, prevent overwriting any files

I would like to use the following routines in my submission script for GAMESS calculations. Before I do, I would like to get some input if I can improve it somehow. The three messaging routines (<...
1
vote
1answer
59 views

Gulp task to increment a major, minor, or patch level of the version number of the last build

Working codepen: http://codepen.io/leongaban/pen/oxwLzE?editors=1010 The function below takes in user entered text through the cli: V=patch gulp build It then ...
1
vote
0answers
56 views

Merging trees in scalaz

I just built a function to merge a set of List[A]s into a single scalaz.Tree[A]. Specifically, if I have the following three <...
0
votes
1answer
29 views

JavaScript function for logging the members of an object (with horizontal alignment)

When iterating over the members of an object for logging the keys / values one gets a "stair case" effect. Therefore I wrote myself this function which takes care for a left-alignment of the values. ...
3
votes
1answer
56 views

Clojure reverse multiple times

I have a piece of Clojure code that reverses a string recursively. It is working but too slow (because I got the problem from Codewars and I cannot validate it ...
2
votes
2answers
48 views

PE # 34 - “Digit Factorials” with no loops

I posted a similar question “Curious Numbers” (HackerRank PE 34) recently (but in a different language/platform altogether). I'm starting to learn JavaScript and decided to take the challenge again ...
3
votes
1answer
40 views

Find zeroes in a matrix

I am looking for the elements that are zeroes in a square matrix (of size n), as a list of pair. I don't really like the following code, some condition seems ...
8
votes
1answer
113 views

“Curious Numbers” (HackerRank PE 34)

I was inspired by a certain recent question to try my hand at this challenge: Project Euler #34: Digit factorials \$19!\$ is a curious number, as \$1!+9!=1+362880=362881\$ is divisible by \$...
5
votes
2answers
97 views

Document term matrix in Clojure

This is my very first foray into Clojure (I'm normally a Python-pushing data-type). I'm trying to create a simple term-document matrix as a vector of vectors, out of a vector of strings. For those ...
4
votes
2answers
117 views

A curry function

I am new to the functional style, and I wrote a curry function to practice this new style. This curry function takes a regular function and returns the curried version of it. Currying is a technique, ...
1
vote
2answers
121 views

Longest palindromes

I've been tasked to solve this exercise lately, and this is what I wrote: ...
4
votes
1answer
62 views

C++ idiom for selecting integers from a vector according to predetermined properties

I want a function Select that takes a vector<int> and a condition (such as being even, being divisible by three, being ...
6
votes
1answer
57 views

All possible ways of merging two lists while keeping their order

I am writing a function gives all possible ways of merging two ordered lists such that in the merged list, the elements are still ordered according to the elements in their respective starting list. ...