logo

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

Difference Between Array.at and Array[idx]

Array.at(idx) is a method introduced in ES2022.

Let’s explore the differences between the traditional Array[idx] and Array.at(idx).

Differences

The most significant difference is the support for negative indices.

const arr = [10, 20, 30]
console.log(arr[-1]) // undefined

const arr = [10, 20, 30]
console.log(arr.at(-1)) // 30
One minute to read