Iterating over Pages of a Specific Section in Hugo

In Hugo, there may be instances where you need to iterate over the pages of a specific section. This can be achieved by targeting the markdown files stored within a folder under the content directory, such as content/mysection. The following code snippet demonstrates how you can accomplish this: {{ range (where .Site.Pages "Section" "mysection") }} {{ range .Pages }} {{ .RelPermalink }} - {{ .Title }} {{ end }} {{ end }} By utilizing the range function along with the where function, you can iterate over the pages of the desired section....

JavaScript Algorithms: Binary Search

Binary search is an efficient algorithm used to search for an item in an ordered array or any other ordered data structure. It reduces the search space by half with each iteration, making it a highly optimized search algorithm. To perform a binary search, follow these steps: Start with the ordered array and the item you need to search for. Calculate the middle index of the array by dividing the number of elements by 2....

JavaScript Algorithms: Bubble Sort

Bubble sort is a simple sorting algorithm with an inefficient worst-case time complexity of O(n^2). However, it is still worth learning about the algorithm. Bubble sort works by looping through an array and comparing each item to the one next to it. If the item on the right is smaller, the two positions are swapped. Here is an implementation of the bubble sort algorithm: const bubbleSort = (originalArray) => { let swapped = false; const array = [....

JavaScript Algorithms: Linear Search

In the world of computer science, the linear search algorithm, also known as sequential search or simple search, holds a significant position. As one of the most fundamental search algorithms, it allows us to locate an item within a data structure, such as an array, by examining each element until a match is found. The implementation of the linear search algorithm is remarkably straightforward: const linearSearch = (list, item) => { for (const [i, element] of list....

JavaScript Algorithms: Merge Sort

Merge sort is a popular sorting algorithm that utilizes the “divide and conquer” approach. In this algorithm, an array is divided into two halves recursively until each half contains only one element. Then, the sorted subarrays are merged to form a single sorted array. Let’s take an example to understand how merge sort works. Suppose we have an array: [4, 3, 1, 2] We first divide the array into two halves:...

JavaScript Algorithms: Selection Sort

Sorting an array of numbers by element size is a common task in programming. One approach to achieve this is by using the selection sort algorithm. The selection sort algorithm works by repeatedly finding the minimum element from the unsorted part of the array and moving it to the beginning. The steps involved in the algorithm are as follows: We start by selecting the first element of the array. We then compare this element with the second element....

JavaScript Assignment Operator: Simplifying Variable Assignment

In JavaScript, the assignment operator “=” is used to assign a value to a variable. This operator provides shortcuts for performing arithmetic operations and assigning the result to the variable. Let’s look at some examples: const a = 2; let b = 2; var c = 2; In the above code, the assignment operator is used to assign the value 2 to the variables a, b, and c. The assignment operator also has shortcuts for arithmetic operations....

JavaScript Coding Style Guide: Writing Clean and Readable Code

This JavaScript Coding Style Guide outlines the set of conventions that I follow when writing JavaScript code. It serves as a live document, constantly updated with the main rules I adhere to in my development work. Developing a consistent coding style is essential for maintaining code readability and ensuring collaboration within a team. Whether you are working solo or as part of a team, establishing and following coding style rules will keep your code in line with industry best practices....

JavaScript Data Structures: Linked Lists - Improve Your Technical Blog

Linked lists are a crucial data structure to learn in JavaScript. They allow us to efficiently store and manage data by connecting each item to the next item in the list. Unlike arrays, linked list items do not need to be stored in adjacent memory locations and cannot be randomly accessed using indices. Since JavaScript does not natively support linked lists, we can create our implementation. To start, let’s create the “Item” class that represents each item in the linked list:...

JavaScript Data Structures: Queue - An Introduction

In JavaScript, queues are similar to stacks but with a different way of handling data insertion and removal. They follow the First In, First Out (FIFO) principle, meaning that the first item to be added is the first one to be removed. Just like waiting in line at a restaurant, a disco, or a concert hall, items are processed in the order they were added. To implement a queue in JavaScript, we can use an array as the internal storage and utilize private class fields for encapsulation....