Skip to main content

All Questions

2 votes
2 answers
293 views

How to correctly identify pure functions in functional programming?

Is this function pure or impure? function greet(name) { return "Hi I'm " + name; } The property of pure function is that it has no side effects and always returns the same output for ...
Devin de Silva's user avatar
2 votes
3 answers
215 views

How is injecting an impure function different from calling it?

I am reading a book where it says one way to handle impure functions is to inject them into the function instead of calling it like the example below. normal function call: const getRandomFileName = (...
risky last's user avatar
1 vote
1 answer
391 views

How to Map an object's values regardless of its keys, and strongly type it (like Array<T>.map)

I'm in ES7/ES8, I want to know how to map an object's values, regardless of its keys (like Array.map). I found this post here But : I am forced to map also the whole object, not the just value I also ...
E-jarod's user avatar
  • 294
0 votes
1 answer
236 views

"Stringly typed" function vs. many redundant functions vs TypeScript's string enum

I have an object in the following structure: const geo = { europe: { germany: ['berlin', 'hamburg', 'cologne'], france: ['toulouse', 'paris', 'limoges'], italy: ['rome', 'venice',...
Emman's user avatar
  • 4,241
0 votes
3 answers
113 views

Why type `Function` doesn't work when typing a higher-order function parameter that accepts a function?

I want to type a function that takes as inputs: array a function for filtering logic (predicate function) In JavaScript, the following works as expected: const myFilter = (func, arr) => arr....
Emman's user avatar
  • 4,241
1 vote
3 answers
78 views

Javascript - Loop two arrays inside another functional way

I have two arrays vehicles and routes, given below const vehicles = [{ name: 'TukTuk', maxSpeed: 12 }, { name: 'Bike', maxSpeed: 10 }, { name: 'Car', maxSpeed: 20 }]; const routes = [{ name: '...
HariHaravelan's user avatar
2 votes
4 answers
228 views

How to extract a function out of arr.map(elem => dict[elem])?

A function should do only one thing is considered a good practice when writing functions. However, I have a function that is already very minimal, but nevertheless I think it can be further extracted, ...
Emman's user avatar
  • 4,241
-1 votes
1 answer
79 views

How to change a function based on unknown number of arguments in javascript

Is there any way to add to or manipulate expressions in a returned function? This is an example for a single argument: function trackByProp(prop) { return function (value) { return value[prop]; ...
Nicholas Foden's user avatar
0 votes
1 answer
321 views

Array Assignment in Functional Programming JS [closed]

When declaring a new local variable inside a function and assigning it to a global variable that is equal to an array, what is better? Option 1: Using the Spread Operator: let globalArray = [1, 2, 4]; ...
Egor Ulybin's user avatar
0 votes
1 answer
974 views

Can a method be a pure function?

I'm learning functional programming. I have a very specific question. Technically can a class method be considered a pure function? Let's say we have an add method: add(a, b) { return a + b }. Is the ...
Florian G's user avatar
  • 617
-1 votes
3 answers
279 views

Can we pass argument to function & access like a props in react

I have started learning to React/JavaScript recently, I found the way props are passed and accessed very interesting, I tried to make a similar JavaScript function in react which can simply take ...
Wasit Shafi's user avatar
  • 1,657
6 votes
1 answer
965 views

Is this JavaScript function, taking a mutable reference argument, a pure function?

I have the same question as this one, but in the context of JavaScript. From Wikipedia: [a pure function's] return value is the same for the same arguments It's further claimed there that a pure ...
mb21's user avatar
  • 39.7k
-1 votes
2 answers
123 views

List self nesting in Javascript

Question I am trying to achieve a function that transforms a list into a second list with two sublist of itself. This function must do so by being called in a chain i.e [1,2,3] => [[1,2,3],[1,2,3]]...
cstml's user avatar
  • 390
4 votes
2 answers
1k views

Recursive calls between two functions

I need to recursive check two objects and keys need to be sorted, so I created two functions. buildObj - get all uniq keys from object, sort them and call buildObjKey on each key buildObjKey - if one ...
Dimabytes's user avatar
  • 536
0 votes
1 answer
58 views

What is the flow of execution with this compose function passed into Javascripts reduce?

I just want to know how reduce works in the case of code below(which was provided by a stackoverflow user in my previous question, i'm asking this question as his code snippet led to me having more ...
SuthanS's user avatar
  • 53

15 30 50 per page
1
2 3 4 5
7