Posts

Showing posts with the label Currying

SOLID / DRY principles

In software development, Object-Oriented Design plays a crucial role when it comes to writing flexible, scalable, maintainable, and reusable code. There are so many benefits of using OOD but every developer should also have the knowledge of the SOLID principle for good object-oriented design in programming. The SOLID principles are designed to help developers design robust, maintainable applications. The five SOLID principles are: Single-responsibility principle - Function and classes should have one job. Open–closed principle - Classes and functions should be open for  extension but not for modification. Liskov substitution principle - Child class can replace parent class Interface segregation principle - This principle is the first principle that applies to Interfaces instead of classes in SOLID and it is similar to the single responsibility principle. It states that “do not force any client to implement an interface which is irrelevant to them“. Here your main goal is ...

Currying in Javascript

Currying is a technique in functional programming where a function is transformed into a sequence of nested functions, each taking a single argument. This allows you to partially apply arguments to a function and create new functions with some of the arguments pre-filled. Here's an example of currying in JavaScript: function add(a) {   return function(b) {     return a + b;   }; } const add5 = add(5); console.log(add5(3)); // Output: 8 console.log(add5(7)); // Output: 12 In this example, the `add` function takes one argument `a` and returns another function that takes a single argument `b` and returns the sum of `a` and `b`. By calling `add(5)`, we create a new function `add5` that adds 5 to its argument. Subsequently, calling `add5(3)` and `add5(7)` will add 5 to 3 and 7, respectively, resulting in the expected outputs. Currying allows for a more flexible and reusable way of creating specialized functions. It enables you to partially apply arguments and create speci...

Popular posts from this blog

Why do we need callbacks

Difference between localStorage and sessionStorage

Scope in javascript