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
27 views

Why my code doesn't work correctly when I put it into function? [on hold]

I have a script named MakeAcatar.php which generates a avatar (something like stackoverflow's avatars) based on two parameters: size (it is size of avatar) hash ...
-1
votes
0answers
15 views

Postfix versus prefix increment explanation [closed]

I am well aware of the varying evaluation and incrementation moments of both post- and prefix incrementation. Still, I fail to understand why this returns zeros only: ...
4
votes
2answers
71 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
36 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 ...
2
votes
1answer
51 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
46 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 ...
2
votes
1answer
28 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
33 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
44 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 ...
0
votes
0answers
30 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
24 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
52 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
46 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
35 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
78 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
91 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
113 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
114 views

Longest palindromes

I've been tasked to solve this exercise lately, and this is what I wrote: ...
4
votes
1answer
59 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
54 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. ...
2
votes
1answer
74 views

Recursive function application

I use a lot T4 templates and want to avoid extra code writing when it could be generated. Currently I have following class: ...
2
votes
0answers
26 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
34 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
73 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
66 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 ...
3
votes
0answers
39 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
54 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 ...
3
votes
1answer
102 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
30 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
66 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
89 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
78 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
28 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 ...
2
votes
1answer
48 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
84 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
54 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 ...
5
votes
0answers
71 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
50 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
73 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
64 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
69 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
126 views

Finding the max sequence finder

Problem Statement Find the max sequence finder. findMaxSequence([3, 2, 3, 4, 2, 2, 4]); ...
3
votes
2answers
25 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
716 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 ...
6
votes
1answer
236 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
180 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
84 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
63 views

Printing patterns in Haskell

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