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)

0
votes
0answers
4 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 : ...
2
votes
0answers
11 views

Extracting data for a tag cloud using Lazy.js

I've just started using Lazy.js, which is my first exposure to a "functional style" javascript library. I'm still utterly lost as to which of the hundred different functional javascript libraries to ...
8
votes
2answers
56 views

Compiler for a minimal LISP dialect to run on the Java Virtual Machine

As the title states, this is a compiler written in C with a ruby build script that translates a minimal LISP dialect and spits out an executable jar file. I designed this LISP dialect and named it ...
3
votes
1answer
54 views

Quick-sort a linked list?

I have a little project where i am implementing an immutable linked-list (not only...) based on a pair-structure like the LISP cons-cell. The linked list works well and is basically wrapping two ...
4
votes
0answers
32 views

Refactored version of Okasaki's skew-binomial heaps in Standard ML

In his book, Purely Functional Data Structures, Chris Okasaki provides an implementation of skew-binomial heaps (p. 137). Unfortunately, the book isn't (legally) freely available anywhere, but his ...
2
votes
1answer
39 views

Functional Scrabble Word Score

Homework: Write a function to score a scrabble word. values is a global dict formatted as values = {'a': 1, 'b': 3,...} The ...
-1
votes
0answers
13 views

Pattern Matching Function Call in Scala [closed]

I am a newbie in Scala and functional programming. I want to call a function several times, with combination of parameters based on two variables. Basically, What I am doing right now is this: ...
3
votes
1answer
74 views

Object-oriented web scraping with Python

I usually write function-only Python programs, but have decided on an OOP approach (my first thereof) for my current program, a web-scraper. Here is the working code I wrote which I am looking to have ...
0
votes
1answer
29 views

ES6 block-scope variable usage

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 ...
4
votes
2answers
56 views

Functional translation of dice simulation

I have tried my hands at "functionalising" a toy problem I had: find the expected number of throws of a six sided die until all sides have been seen (the answer is 14.7) My starting point is my ...
5
votes
1answer
83 views

Option<T> functional type implementation and scenarios

Have you ever being implementing Option<T> functional type? It is discussed here. Basically, it is about using ...
0
votes
1answer
39 views

Functional Javascript Practice with AJAX

I am currently doing projects in freecodecamp.com to brush up on my javascript skills and just finished a weather report widget. It does the following: Gets api ...
0
votes
0answers
20 views

PBKDF2 and HMAC implementation in Scala

First of all: I know that rolling your own cryptographic functions is bad. The SHA256 implementation i use is from Bouncycastle, but i think both HMAC and PBKDF2 are not vulnerable to timing attacks ...
1
vote
1answer
10 views

Implementing an inner product using pyspark

I'm trying to implement a dot product using pyspark in order to learn pyspark's syntax. I've currently implemented the dot product like so: ...
2
votes
1answer
81 views

Grouping an array by postId and userId

I've got this kind of data: [ { userId: 1, postId: 1, ... }, { userId: 1, postId: 2, ... }, { userId: 2, postId: 3, ... }, ... ] And I need to group them ...
1
vote
2answers
50 views

High order functions on Array.prototype

In order to better understand functional programming in Javascript, I thought I'd try to recreate (as well as extend) some of the higher order functions on the Array object. These methods don't intend ...
4
votes
0answers
42 views

In-lining InvocationExpressions

This is regards to one of my answers: Linq Expression Calling Combines. The question wasn't very well received, but it proved to be an interesting task that I enjoyed working on. I ended up with the ...
0
votes
2answers
44 views

Adding polynomials represented as maps

I'm using maps to represent a polynomial. The key is the exponent and the value is the coefficient : Map(exp -> coef) e.g. ...
5
votes
1answer
66 views

Project Euler problem 11, finding adjacent numbers with the greatest sum

The full description of the problem to solve can be found here. The code I have written works fine but seems extremely verbose for what it's doing, I'm not sure if list comprehensions are meant to be ...
4
votes
2answers
56 views

FizzBuzz functional implementation

I was playing around with ES6 arrow functions, currying and partial application and I decided to try a functional implementation of the FizzBuzz problem: ...
0
votes
2answers
52 views

Write an anonymous function validating email address

Problem statement Write an anonymous function which take email address as parameter and returns true/false after validating the input parameter. Objective This assignment will help ...
5
votes
1answer
38 views

Binary to ascii mapping in JavaScript

This morning I've seen this on Twitter: http://mynewtechworld.tumblr.com/post/135545896048 I case that somebody can't see the image: I 01101100 01101111 01110110 01100101 you. Just ...
4
votes
4answers
86 views

Finding the max sequence finder

Problem Statement Find the max sequence finder. findMaxSequence([3, 2, 3, 4, 2, 2, 4]); ...
3
votes
2answers
22 views

OOP, FP and IMP condensed in Rock, Paper and Scissors

Rock Paper and Scissors is a pretty basic program. The reason I wrote this program is because I wanted to see what a small script that used all of the main programming paradigms looked like. My code ...
14
votes
4answers
702 views

Project Euler 6: Difference between sum of squares and square of sum

I've created a (very) simple solution for Project Euler problem 6: Project Euler Problem 6: Sum square difference The sum of the squares of the first ten natural numbers is, $$ 1^2 + 2^2 ...
5
votes
1answer
206 views

Project Euler Problems #1-#5

Since I've been playing with F#, I decided to try my hand at implementing some of the Project Euler problems, and I've been having a blast doing it. (f#-is-fun) So, I'm going to list all the Project ...
3
votes
1answer
103 views

RxJS Subscription Service in Webworker

Here is a plunker of my working demo. I have the following code which I have created for a subscription service for data through a webworker. I was wondering if I was following functional-reactive ...
21
votes
6answers
3k views

To 'this' or not to 'this'?

I was given a homework and I have 2 solutions: one that uses this and other one that doesn't. I tested it on jsPerf but sometimes it says the version with ...
2
votes
2answers
65 views

Reduce array of objects into object of arrays

I have an array of objects where each object has two keys: key (k) and value (v). I need to make an object that would take ...
10
votes
1answer
62 views

Printing patterns in Haskell

Write a function Int -> Char -> Char -> [String] that will create the appropriate pattern. For example: ...
4
votes
4answers
200 views

Mastermind: Evaluating the guess

The evaluate_guess function below returns the evaluation of a guess with respect to Mastermind game rules: ...
6
votes
1answer
75 views

Game of Life rules in 14 lines of Python

I've attempted a functional solution to Conway's Game of Life in Python. The example code allows you to see the next generation of the universe by calling the ...
6
votes
1answer
63 views

Improving multiple assignment using an iterator function

Often I need to perform multiple assignment from a sequence (e.g. from the result of a split()) but with some semantics that, AFAIK, are not available in the ...
1
vote
1answer
51 views

Currying addition function in ECMAScript 6

I wanted to write an add function that implemented currying in JavaScript. I welcome criticism and suggestions for improvement. ...
1
vote
1answer
118 views

Ordered dictionary in swift 2

Loosely basing myself on this blog post, I implemented an ordered dictionary. In essence, it's a wrapper struct for a list of tuples with some initialisers and some functions (map, filter, toArray, ...
0
votes
1answer
52 views

Naive Bayesian Implementation C++

For my assignment, I have to take a data set and stratify sample it into three different training sets (one with 10%, one with 30%, and 50%). Then I have to classify it using a Naive Bayesian ...
3
votes
3answers
41 views

Visualize the runtimes of list algorithms

I wrote a small script to visualize the runtimes of list algorithms. The script works by creating a list of lists with sampled lengths from 1 to max_size. Next, I ...
2
votes
1answer
50 views

Sum an array of video lengths in JavaScript into HH:MM:SS

I am trying to learn functional programming in JavaScript, and saw a little task on Twitter that I wanted to have a go at: ...
2
votes
1answer
124 views

AngularJS code to query DB and update $scope

I have an AngularJS function that is used to determine which $scope associative array variable is to have data pushed into it. I would love to be able to remove the ...
1
vote
1answer
70 views

Early-termination foldLeft for Scala Streams

The foldRight and foldLeft methods for Scala Streams cannot terminate early, so here is my ...
1
vote
2answers
74 views

Prime factor tree

Design a program that finds all numbers from 1 to 1000 whose prime factors, when added together, sum up to a prime number (for example, 12 has prime factors of 2, 2, and 3, which sum to 7, which is ...
5
votes
1answer
118 views

FizzBuzz in JavaScript using Ramda

Just getting up to speed in Ramda, I have implemented this: ...
1
vote
1answer
47 views

Map all symbols in module to dictionary

The div and add functions are located randomly in my package structure. I have a function with this signature: ...
3
votes
2answers
60 views

Bubble sort in Scala

I wanted to implement a bubble sort in Scala following the steps described in: http://www.bbc.co.uk/education/guides/z22wwmn/revision/3 ...
1
vote
2answers
87 views

Scraping and using JSON data from thousands of files in a directory

I have a few thousand json files containing order histories sitting in a directory from one of our systems. Since customers can opt in to receive marketing I'm opening each json file and then ...
2
votes
2answers
48 views

Summations and products, and factorials oh my

The proper title of this question should be "Summations and products, and factorials oh my!". After getting quite a bit of useful feedback on this question from @mjolka, and a comment, I decided ...
0
votes
1answer
33 views

php most elegant function call returning array [closed]

I am asking your preference between two similar solutions. First way : ...
4
votes
2answers
305 views

Password generator script

What I was trying to do here was create a Python script that would generate passwords with 16 characters with uppercase and lowercase letters, and numbers. The generated password would then write ...
3
votes
1answer
77 views

Trying to do Type-Driven Development in F#

I've been wanting to try out F# for some real world programming so I decided to try rewriting a program that is being used at work. It can be reduced to a few steps: Get report templates. In this ...
1
vote
2answers
101 views

Number to german decimal format converter function [closed]

I have a function that formats a number (even a float) to a German decimal format. I got this function from here ...