logo

Closures in React

Closures are a fundamental concept in JavaScript.

It’s a concept that is often asked about in technical interviews, and I remember memorizing it while preparing for my own technical interviews.

However, I didn’t quite understand how closures are used in practice, and I often pondered how to apply them effectively. This time, I want to study the concept of closures in more depth.

Problem

When passing a function as a parameter to customHook, let’s observe how the state value inside the function is output when the useCustom component is unmounted.

2 minutes to read

Array Using Set

Using Set

The main difference between using a regular array and a Set is how they handle duplicate elements.

let setArr = new Set(['a','b','c','d','a'])

console.log(setArr)
// 출력: Set(4) { 'a', 'b', 'c', 'd' }
  • A Set is a data structure that does not allow duplicates.
  • This means that even if you try to add the same value multiple times to a Set, only one instance of that value will be kept.
  • To convert a Set into an array, you can use Array.from().
let report = ["muzi frodo", "apeach frodo", "frodo neo", "muzi neo", "muzi frodo"];
let uniqueReports = new Set(report);

console.log(uniqueReports); 
// 출력: Set(4) { 'muzi frodo', 'apeach frodo', 'frodo neo', 'muzi neo' }

Characteristics of Set

One minute to read

Permutation

Permutation is a concept learned in high school mathematics.

At that time, I memorized the formulas without really understanding what permutations were or when to use them (I guess that’s why I didn’t study well as a kid…)

What is a Permutation?

A permutation refers to arranging all the elements of a set while considering the order.

In other words, it refers to all possible arrangements of n given elements in all possible orders.

2 minutes to read