Learn how to remove loops and use higher-order functions like map, reduce, and filter Image by Lysander Yuen Why Are We Replacing Loops? Using higher-order functions will make your code : More readable. Easy to understand. Easy to debug. 1. To Loop Through All Elements and Get an new modified array Using loop: var names = [“Jack”, “Jecci”, “Ram”, …
Tag Archives: Angular
Generating Random Numbers in JavaScript
It’s more than Math.random() Image by NeONBRAND The Math.random() will generate a pseudo-random floating number (a number with decimals) between 0 (inclusive) and 1 (exclusive). Here, the random number doesn’t mean that you always get a unique number. It generates the same number only after some interval. The interval here is very long, so you …
Different Ways to Duplicate Objects in JavaScript
It turns out there are a lot of different ways to duplicate objects Photo by James Orr on Unsplash In JavaScript, a variable can store two types of data: Primitive Reference When we copy primitive values, only the value will be copied. var a = 10; var b = a; console.log(a, b); // 10, 10 b …
Continue reading “Different Ways to Duplicate Objects in JavaScript”
Implementing a Stack in JavaScript
They’re like arrays with more structure and rules Image by Brooke Lark from Unsplash Stacks are data structures that follow the Last-In-First-Out (LIFO) principle, meaning the last item inserted into a stack is the first one to be deleted. In other words, a stack is a list of elements that are accessible only from one end of …