2
votes
1answer
24 views

PureScript does not compose `trace` and `show`

So the following works main = do trace $ show $ 5 but this does not main = do (trace . show) 5 in psci the type of trace is forall r. Prim.String -> Control.Monad.Eff.Eff (trace ...
0
votes
1answer
15 views

Flatten only first layer of array

I worked very hard on creating my own flatten function using functional programming. I have it all working except for some reason false is not being included in the answer. I am trying to input it as ...
1
vote
3answers
31 views

merging two data structures of different shapes

I have two data structures with different shapes that come from two different API's. The data is in JSON format, language is JavaScript. Array 1: [ { "document" : { "html" : "some_html", "name" : ...
1
vote
1answer
32 views

Applying prototype function in function composition

I want to understand how to use _.compose, and for example turn something like this: url.substr(url.indexOf('?')) into composition, something maybe like: var c = _.compose(String.substr, ...
0
votes
1answer
55 views

Bacon.js “splitting” an event containing an array into multiple events for each element

I've recently discovered Bacon.js and have been tinkering but struggling with an issue. I have an event stream results for recent GitHub users returned from an AJAX request. Each result event is as ...
0
votes
2answers
30 views

how to change private variable from global scope ? Is it possible?

Is it possible to change localVar local variable of below function from global scope function test(){ var localVar = 'I am a local variable !'; console.log(localVar) } UPDATE If it is a ...
0
votes
0answers
13 views

Rx JS Subscribe Observer to multiple Observables

Scratching the surface of Rx JS I ve ended up with the following snippet: var observer1 = Rx.Observer.create( function (x) { console.log('Next: ' + x); }, ...
0
votes
1answer
28 views

Is there any cool method to define/calc PI using lazy evaluation sequence?

I use lazy.js on javascript. I wonder if there's a cool method to define (not actually calc) PI empowered by lazy evaluation. I know lazy-evaluation is call-by-need, but how do you define PI in the ...
0
votes
3answers
43 views

underscore or lazy.js map (0,1,2,3,4) + (1,2,3,4,5) ->(1,3,5,7,9)

I want to map a sequence to another sequence such as map (0,1,2,3,4) + (1,2,3,4,5) -> (1,3,5,7,9) How to do that in lazy.js or underscore ? Thanks!
1
vote
0answers
23 views

pure functional javascript - solving sample prob

I wrote a decodeMsg function which was given as a problem on codeeval, here's my code: http://bit.ly/1rDIvCh It works but I'm trying to learn and get more into pure functional javascript. I would ...
0
votes
1answer
14 views

Capturing and Triggering same event on Fail

I want to capture an event and trigger it conditionally. $('#next, #prev, .qpn').click( function(event){ if (status[0]){ submit_quiz($(currQ), 0); } else{ ...
0
votes
2answers
70 views

I don't understand Crockford on Javascript: The Way Forward

In a lecture called "The Way Forward", Douglass Crockford shares that he no longer uses "new" in his JavaScript, and is weaning himself off of "this". He says JavaScript's good feature was not so ...
0
votes
3answers
38 views

Use my function in itself and return in 'correct' order

I have this function var foo = function(){ var args = Array.prototype.slice.call(arguments, 0); for (var i = 0; i < args.length; i++) { console.log(args[i]); } }; that's used like ...
0
votes
3answers
29 views

Where does the value in my function come from?

I am currently working my way through the functional JavaScript exercise at http://nodeschool.io. I have the following exercise: Return a function that takes a list of valid users, and returns a ...
1
vote
1answer
27 views

Why does using Array.map(parseInt) on an array of strings produce different results

I was watching a talk on destroy all software title The Birth and Death of Javascript during the talk Gary Bernhardt pointed out a JavaScript quirky features, were given an array of integer strings, ...
-4
votes
2answers
45 views

javascript IDE, What should i pick? [closed]

i want to know what IDE do you recommend for execute javascripts codes? for(var i = 0; i < 120; i+=2){ console.log(i); }
1
vote
3answers
47 views

Pass a nested function as a parameter

Is there a way nest functions and pass them as a parameter? I have this 2 functions: function mayus(string) { return string.toUpperCase(); } function removeA(string) { return ...
0
votes
1answer
41 views

partial class methods in node.js using lodash?

I would like to create a function in node.js which takes an integer value and converts it into a binary string using lodash/underscore's _.partial/_.partialRight. var _ = require('lodash'); var n = ...
1
vote
3answers
155 views

Advantage of Functional Reactive Programming over event-listeners

I've been hearing a lot about functional reactive programming, and decided to check out what the big deal is. Going through the bacon.js documentation, it seems that the main difference is that ...
3
votes
0answers
123 views

Current State of JavaScript Functional Programming Libraries [closed]

The Libraries Low Dash Underscore inspired, fixes lots of stuff apparently, great API Apparently it was so inspired by underscore that its also doing it wrong! fn.js Currently under 1.0 but great ...
0
votes
2answers
97 views

Functional way of joining two js object arrays based on common id

I am trying to acheive something similar to SQL table join, in the most elegant (functional) way, preferably with underscore.js, so no for loops please. I need to merge objects from two different ...
0
votes
0answers
15 views

Will this conditional in wu.autoCurry ever be met?

Below is the function. I just don't see how the "else" of that ternary operation could ever get executed, but if I'm missing something I'd like to know wu.autoCurry = function (fn, numArgs) { ...
-1
votes
2answers
119 views

Should I learn haskell for understanding the functional programming part of javascript? [closed]

I'm a developer with very strong oop background. And Recently I want to learn javascript coz I think it's the future. But I find myself very hard to understand the functional programming part of ...
2
votes
2answers
85 views

How does Function.bind.bind(Function.call) uncurry?

We have this line in my code base: var uncurryThis = Function.bind.bind(Function.call); That I'm trying to work through. Presumably, it uncurries. How do I work this out? I guess it's a version of ...
0
votes
1answer
47 views

Why use apply in an UnderscoreJS-enabled rename function?

I am reading Functional Javascript, which relies heavily on Underscore for its examples. One example, in particular, is confusing to me. The author uses apply within a function twice: firtst, to ...
2
votes
1answer
65 views

Scala return value not what is expected

I am learning Scala as a personal interest and I'm perplexed by the return value of the following, of which I expect to eventually print 52: def lexicalTest(a: Int) = { (b: Int) => { (c: ...
0
votes
2answers
224 views

How to set a value to a global variable inside a function in javascript/angular?

Well, I need to use a variable in different angular controllers or any function, which I can do, but in this particular case I'm getting the value of one of those variables from a service or a ...
0
votes
1answer
65 views

How do I execute a function only once in CoffeeScript

I want to make a CoffeeScript function that even if it is invoked multiple times, has its effects only run once. Is one of these, or another way a good way to make a once-invokable function ? Is the ...
1
vote
1answer
71 views

Applicative functors in Underscore/Lo-Dash chaining - how to map inside a map?

I have a nested object like this: var itemsWithQuantities = [ { Identifier: 'SomethingWithQuantities1', Quantities: [ { Name: 'Quantity 1', Amount: 4 }, { Name: 'Quantity 2', ...
3
votes
1answer
63 views

What are the benefits / drawbacks of functional object creation in JavaScript?

I just watched Douglas Crockford talk about how prototypical inheritance is "not a good idea either" YouTube 35m55s I don't really care about his views on Prototypical inheritance in conjunction ...
0
votes
2answers
40 views

Explaining the benefits of using a high-order function in a simple English language

Consider this example, i need to know the benefits of using a high-order function as so: function bind(func, object) { return function(){ return func.apply(object, arguments); }; } I mean ...
0
votes
0answers
54 views

Condensing a collection of objects using Underscore.js

Use Case Given a collection of objects, I am interested in combining all these objects into a single object with an aggregation of all the properties. This is very similar to the _.extend function ...
0
votes
0answers
81 views

UnderscoreJS find-and-replace

In my application, I have a very large array of objects on the front-end, and these objects all have some kind of long ID under the heading ["object_id"]. I'm using UnderscoreJS for all my ...
1
vote
2answers
41 views

Looking for an FP algorithm to compose objects from dot-separated strings

I am trying to solve a specific problem using functional programming. My guess is that a fold should do the job, but so far the solution has eluded me. Starting from a dot-separated string like ...
2
votes
1answer
143 views

Is applying functional programming principles to Javascript a seriously viable option?

I come from a background in Haskell. I'm very used to getting things done with recursive functions and the typical higher-order functions (folds, maps, filters, etc) and composing functions together. ...
2
votes
1answer
63 views

Given an array of arrays, I want to call a function passing each array as arguments

I have an array of arrays: var data = [[2,2], [6,4], [300,500]]; I have a function that takes some arguments and returns a single value. var sum = function (a, b) { return a + b; } I want to ...
1
vote
1answer
103 views

Functional Javascript example of higher-order functions using plucker, reduce and finder functions

I'm going through the book Functional Javascript by Michael Fogus. In chapter 4, he creates a function, titled finder, which utilizes reduce. I'm having difficulty grasping the implementation of this ...
0
votes
1answer
67 views

Clean way of keeping an aggregate of a sequence of Q.all promises

I would like to maintain an aggregate of intermediate results when executing a series of Q.all tasks. Concretely the problem is as follows: var Obj = function(first, second) { return { ...
2
votes
2answers
30 views

PHP vs JavaScript: Altering the value of an array passed in gives different results

It was very difficult to come up with an informed title for this post. Though PHP and JS are totally different languages, I am very surprised to find that altering an array passed into a function as ...
0
votes
3answers
83 views

Create an array with all numbers from min to max without a loop

I have two numbers, min and max, and I want to create an array that contains all number between them (including min and max). The most obvious approach is to use a for loop for this, and push the ...
0
votes
1answer
73 views

Using an external functional language for data processing in node.js

I'm working on a project that at some places would benefit greatly in code cleanliness if the problems were solved in a functional style. Now, Javascript is for the most part fully capable of doing ...
1
vote
1answer
26 views

Getting data back out of closures

Is there a way to extract a variable that is closed over by a function? In the (JavaScript-like) R language values that are closed-over can be accessed by looking up the function's scope directly. ...
0
votes
0answers
21 views

Can someone explain to me why in certain formulas, no 1 subscript is output at the end?

SO I'm making a PHP/JS program which will do chemical calculations, and I have got some of it working. Unfortunately, when I run the program at the moment, the very last element in a formula, what I ...
1
vote
2answers
77 views

lodash.js partial application on function.apply

Given the following function, the usage of _.partial function throws an error: function foo(x, y) { return 1 + 2; } p = _.partial(foo.apply, null); p([1,2]); I get: TypeError: ...
3
votes
2answers
55 views

Javascript functional programming quiz

Here is the problem. I have to implement make function: var sum = function (a, b) { return a + b; } var mult = function (a, b) { return a * b; } //'make' function goes here var res = ...
-2
votes
2answers
39 views

Javascript challenge - How to call a function such that it returns 8?

Long time ago I saw a Javascript challenge, I do not remember where, but now I am trying to solve it. Until now, I do not know how to proceed. I have this function and I have to make a call such that ...
0
votes
1answer
67 views

Understanding the “fnull” function and the arguments within “fnull”

Problem I'm learning functional programming using the book "Functional Javascript". Currently, I'm fairly puzzled by the console output from the fnull method. I'm looking for an explanation to what ...
0
votes
4answers
54 views

Transtale jquery event's this to a function parameter

I have been wondering about a particular case when using jQuery's this on events. Lets say we have the following function: function myPrint(randomString){ console.log(randomString); } And we ...
0
votes
2answers
354 views

How to join arrays using Lo-Dash

Since I’m trying out Lo-Dash, I’m wondering how to join and sort two arrays? A1: [ 3, 1 ] A2: [ { 1: ‘val 1’ }, { 2: ‘val 2’ }, { 3: ‘val 3’ }, { 4: ‘val 4’ }, … ] A1 join A2 orderBy Vals: [ { 1: ...
0
votes
1answer
83 views

Trampoline, recursion and lazy evaluation

I'm trying to implement basic lazy sequences in JavaScript. I'm only using closures and continuations. This is what I got so far: var cons = curry(function(x, y, list){ return list(x, y); }); var ...