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.
0
votes
1answer
18 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
45 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
80 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
37 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
19 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 ...
0
votes
0answers
5 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
44 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
40 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
41 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
55 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
49 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
80 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
700 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
195 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
90 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
61 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
61 views
Printing patterns in Haskell
Write a function Int -> Char -> Char -> [String] that will create the appropriate pattern.
For example: ...
4
votes
4answers
192 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
73 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
105 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
50 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
39 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
101 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
67 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
64 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
114 views
1
vote
1answer
46 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
57 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
80 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
47 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
32 views
php most elegant function call returning array [closed]
I am asking your preference between two similar solutions.
First way :
...
4
votes
2answers
259 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
75 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
91 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 ...
2
votes
1answer
50 views
Summations and products in F#
I was bored, and looking to do something that involved anonymous functions, and it was suggested by @Quill, that I create a summation function. I decided to also include a product function as well to ...
4
votes
4answers
130 views
Calculating average grades
I'm a C# developer looking to learn more about Python and how to think in a more functional programming manner.
I have the following which takes a series of grades and returns the average:
...
1
vote
0answers
51 views
2
votes
1answer
64 views
Golden Section Search in Lisp
I implemented the golden section search algorithm recursively in Lisp. My code is:
...
7
votes
1answer
94 views
Functional-style list in C++
I've implemented a functional-style list structure in C++. It seems okay so far, and doing custom allocation for list nodes improves performance greatly. I omitted that part here for simplicity.
The ...
2
votes
1answer
134 views
Functional pattern matching in C#
I recently read a really interesting post on adding functional pattern matching to C#. Here's a quick and dirty implementation using delegates and dictionaries.
Right now, I require that ...
4
votes
1answer
69 views
Extending SeqLike - move an element to the front of the sequence
I wrote a method called bringToFront, which moves an element a to the first position of a sequence ...
7
votes
1answer
107 views
Small game written in F#
I'm trying to wrap my head around F#. I'd like your honest opinion about this simple game source code that I wrote. Rules are simple:
Every player has soldiers and territory
Player can recruit ...