teleren/devto huggingface dataset:
Data Structure and Algorithms JavaScript
Published: 2022-07-25 18:16:00

## **Linear Search:**
function search(arr, value) {
    for (let i = 0; i < arr.length; i++) {
        if (arr[i] === value) return i
    }
    return -1
}

console.log(search([2, 11, 23, 44, 9], 23)) 
Answer: 2


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/exvc87fkgnykh28wz9w4.png)

             😊😊😊😊😊😊😊😊

## **Binary Search:**
function binary(arr, value) {
    let start = 0
    let end = arr.length - 1
    while (start <= end) {
        let middle = Math.round((start + end) / 2)
        if (arr[middle] === value) return middle
        if (value > arr[middle]) {
            start = middle + 1
        }
        else if (value < arr[middle]) {
            end = middle - 1
        }
    }
    return -1
}

console.log(binary([2, 3, 5, 8, 11, 44, 76, 88], 44))
Answer: 5


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/idmpe4g248269e9pnm11.png)

                      😊😊😊😊😊😊😊😊

## **Bubble Sort: O(n2)**

function bubble(arr) {
    let isSwap;
    for (let i = 0; i < arr.length; i++) {
        isSwap = false
        for (let j = 0; j < arr.length - i - 1; j++) {
            console.log(arr[i], arr[j])
            if (arr[j] > arr[j + 1]) {
                let temp = arr[j]
                arr[j] = arr[j + 1]
                arr[j + 1] = temp
                isSwap = true
            }
        }
        if (!isSwap) break
    }
    return arr
}
console.log(bubble([2, 1, 4, -22, 55, -1])) //[ -22, -1, 1, 2, 4, 55 ]



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ajhrgbkvceqxwfx1cqh.png)

                     😊😊😊😊😊😊😊😊

## **SelectionSort:**

function selectionSort(arr) {
    for (let i = 0; i < arr.length; i++) {
        let lowest = i
        for (let j = i + 1; j < arr.length; j++) {
            if (arr[lowest] > arr[j]) {
                lowest = j
            }
        }
        if (i !== lowest) {
            let temp = arr[i]
            arr[i] = arr[lowest]
            arr[lowest] = temp
        }
    }
    return arr
}
console.log(selectionSort([1, -2, 33, 11, 5]))



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uffxncuhmoqpxjr2tx4o.png)


                 😊😊😊😊😊😊😊😊

## **Insertion Sort:**

function insertionSort(arr) {
    for (let i = 1; i < arr.length; i++) {
        for (let j = i; j > 0; j--) {
            if (arr[j] < arr[j - 1]) {
                let temp = arr[j]
                arr[j] = arr[j - 1]
                arr[j - 1] = temp
            } else {
                break
            }
        }
    }
    return arr
}
console.log(insertionSort([2, 9, -1, 22, -11, 29])) //-11, -1, 2, 9, 22, 29 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ne60a8sjtjwmm34ft8qi.png)
Url in Javascript
Tags: javascript, programming, webdev, tutorial
Published: 2022-07-25 18:14:15

In javascript you can easily create a new URL using the below code


```
const url = new URL('https://github.com/DhanushNehru')
url.searchParams.set('tab','repositories')
```

The url.searchParams.set is used to set param values to the url

```
console.log(url.toString())

// Output: https://github.com/DhanushNehru?tab=repositories
```

This URL API is safely supported in all modern browsers.

Hope you learned something new. Thank you for reading ❤️ 

For more insights connect with me via [Twitter](https://twitter.com/Dhanush_Nehru) & [Github](https://github.com/DhanushNehru)
How do you decide when to get your next computer?
Tags: discuss, anonymous, help
Published: 2022-07-25 18:05:46

_This is an anonymous question sent in by a member who does not want their name disclosed. Please be thoughtful with your responses, as these are usually tough posts to write. Email sloan@dev.to if you'd like to leave an anonymous comment or if you want to ask your own anonymous question._ 

***
Web Scraping Research Oriented
Tags: python, scraping, webdev, computerscience
Published: 2022-07-25 17:45:00

Wanna deep dive in web scraping from beautifulSoup to Selenium.

We have made our own examples to get deep dive in these topics as well as we have scraped Zameen.com (House website), Indeed.com (Job website), The News International (News wesbsite), GitHub.com with API and with main page, Youtube comments and custom celebrity's tweets from Twitter.

I have provided my assistance to my university professor.

You can find these lectures and related codes on this playlist:
https://lnkd.in/dxFiRfq4
("Graph") 797. All Paths From Source to Target
Tags: backtracking, java, algorithms
Published: 2022-07-25 17:27:45

Given a **directed acyclic graph** (DAG) of n nodes labeled from 0 to n - 1, find all possible paths from node 0 to node n - 1 and return them in any order.
 
The graph is given as follows: graph[i] is a list of all nodes you can visit from node i (i.e., there is a directed edge from node i to node graph[i][j]).

**Example**: 
![graph](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2r8cufzyi84jl6czcaej.jpg)

```
Input: graph = [[1,2],[3],[3],[]]
Output: [[0,1,3],[0,2,3]]
Explanation: There are two paths: 0 -> 1 -> 3 and 0 -> 2 -> 3.
```

```java
class Solution {
    public List<List<Integer>> allPathsSourceTarget(int[][] graph) {
        // we have to find all the possible path from source to destination.
        // we can do that with depth first search.
        //we can keep track of visited nodes in a list in a depth first search manner.
        //if we reach the target node we will store list 'l', and we will backtrack to adjacent nodes of the previous node to check all the possible paths
        List<List<Integer>> list = new ArrayList<>();
        dfs(0,graph,new ArrayList<>(Arrays.asList(0)),list); //initially we are also adding 0 in the list l, as the starting node
        return list;
    }
    public void dfs(int node, int[][] graph,List<Integer> l, List<List<Integer>> list){
        if(node ==graph.length-1){
            list.add(new ArrayList<>(l));
            return;
        }
        // below loop will give array of all adjacent nodes of current node i.e 'node'
        for(int i : graph[node]){
            //take
            l.add(i);
            dfs(i,graph,l,list);
            //don't take
            l.remove(l.size()-1);
        }
    }
}
```
Shortest distance from source to all other nodes in a Directed Acyclic Graph
Published: 2022-07-25 17:25:49

 `Shortest path` in a `Directed Acyclic graph` from source to all other nodes can be achieved using **Topological sorting followed by breadth first traversal of the graph** (We will required stack to store the topological sorting and on the stack we will do breadth first search to get the shortest distance. 
**The reason of using topo sort is simple, we save a lot of time by starting from the start point, instead of starting from any random point. Since we know via topo sort we get to know the starting point, hence it becomes optimal to use topo sort!**)

**Solution**: Time complexity is `2*O(n+e)` where `n` is nodes and `e` is edges 2 because `o(n+e)` for topo sort and `o(n+e)` for breadth first search
Space complexity is `o(n)` for visited, `o(n)` for distance, `o(n)` for stack space of topo sort and `o(n)` for `Stack<Integer>` = `4*o(n)`
```java

 private int[] shortestPath(ArrayList<ArrayList<Pair>> adj,int N){
	// here pair will store edge weight between two nodes having and edge
	//example if u and v have and edge with weight 3, => u.add(new Pair(v,5)); like this.
	// first we will have to identify the source or the starting point in the graph
	// so that distance of traversing all other nodes will be smaller from this node.
	// for this we will use topo sorting
	Stack<Integer> stack = new Stack<>();
	int visited[] = new int[N];
	for(int i =0;i<N;i++){
		if(visited[i] ==0){
			dfs(i,adj,visited,stack);
		}
	}
	//now the stack will have topo sorted nodes of the graph.
	//now we will do breadth first search for getting shortest path from source to 
	// all the other nodes in the graph.
	int distance[] = new int[N];
	// source node will be
	int source = stack.peek();
	Arrays.fill(distance,Integer.MAX_VALUE);// distance of all other nodes from the source will be infinite initially.
	distance[source] = 0;// source distance will be zero 
	while(!stack.isEmpty()){
		Integer  i = stack.pop();
		if(distance[i]!=Integer.MAX_VALUE){ // just to make sure that that current node is reachable
			for(Pair pair : adj.get(i)){
				if(distance[pair.getKey()]> distance[i]+ pair.getValue()){
					distance[pair.getKey()] = distance[i] + pair.getValue();
				}
			}
		}
	}
	return distance; /// for any node if the distance comes as Integer.MAX_VALUE then that node is not reachable from the source node.
}

public void dfs(int node, ArrayList<ArrayList<Pair>> adj, int[] visited,Stack<Integer> stack){
	visited[node] = 1;
	for(Pair i : adj.get(node)){
		if(visited[i.getKey()] ==0) dfs(i.getKey(),adj,visited,stack);
	}
	stack.push(node);
}
class Pair{
    private int key;
    private int value;
    public Pair(){
        super();
    }
    public Pair(int i,int j){
        this.key = i;
        this.value =j;
    }
    public int getKey(){
        return this.key;
    }
    public int getValue(){
        return this.getValue();
    }
}
```
Paracetamol.js💊| #176: Explica este código JavaScript
Tags: javascript, webdev, spanish, programming
Published: 2022-07-25 17:24:15

## **<center>Explica este código JavaScript</center>**
#### <center>**Dificultad:** <mark>Básico</mark></center>

```js
if(true){
  var x; // declaración
  x = 3; // asignación 
  var x = 4; // re-declaración y re-asignación
}
console.log(x); // imprimimos fuera del bloque
```

A. `SyntaxisError`
B. `4`
C. `3`
D. `ReferenceError: x is not defined`

Respuesta en el primer comentario.

---
Shortest Distance from source to all other nodes in the graph where the edge weight is 1 unit
Published: 2022-07-25 17:23:54

```java
 private void shortestPath(ArrayList<ArrayList<Integer>> adj,int N,int src){
	// we have to find the shortest Path from given source to all the 
	//other nodes in the graph.
	//let's initialize all the distances from the source as infinity.
	int distance[] = new int[N];
	for(int i =0;i<N;i++) distance[i] = Integer.MAX_VALUE;
	// we will put source distance as 0 as its a starting point
	distance[src] = 0;
	//now we will use breadth first search for finding the shortest distance from 
	//source to all other nodes
	Queue<Integer> q = new LinkedList<>();
	q.add(src);
	while(!q.isEmpty()){
		Integer node  = q.remove();
		//getting distance of all the adjacent nodes of current node
		for(Integer i : adj.get(node)){
			if(distance[i]> (distance[node] + 1)){
				distance[i] = distance[node]+1;// since distance of adjacent node will be distance of current node from source + unit distance i.e. 1
				q.add(i);
			}
		}
	}
	for(int i =0;i<N;i++){
		System.out.println("distance of "+i+" from source " +src+" is "+ distance[i]);
	}
}
```
[Algorithms] 7 - My Solution for Palindrome Linked List with O(N) Time Complexity & O(1) Space Complexity
Published: 2022-07-25 17:11:00

[Link for the problem](https://leetcode.com/problems/palindrome-linked-list/)

# My understanding for the problem

- Idea: Reverse the nodes as slow pointer moves forward. Once the fast pointer reaches to the end of the list, then we compare the nodes from where the slow pointer is at and the nodes that are reversed.
- Edge cases: 
  - What if the list has odd number of nodes? ex) [1,2,3,4,5]
    - The method that I used to figure out if the number of nodes is odd or even:
      - If fast pointer's next exists => even
      - If fast pointer's next does not exists => odd
  - When the list has only one node => true (2 does not matter)

```cpp

class Solution {
public:
    bool isPalindrome(ListNode* head) {
        ListNode* dummy = new ListNode();
        ListNode* slowPrev = dummy, *slow = head, *slowNext = slow, *fast = head;
        dummy->next = head;
        bool isOdd = false;
        
        while(fast){
            
            // Move fast forward
            if(fast->next){
                fast = fast->next->next;
            }else{
                fast = fast->next;
                isOdd = true;
            }

            // Reverse slow
            slowNext = slow->next;
            slow->next = slowPrev;
            slowPrev = slow;
            slow = slowNext;
        }
        
        // Detach dummy node (otherwise will get memory access error)
        head->next = nullptr;
        delete dummy;
    
        if(isOdd){
            slowPrev = slowPrev->next;
        }

        while(slowPrev && slow){
            if (slow->val != slowPrev->val) return false;
            slowPrev = slowPrev->next;
            slow = slow->next;
        }

        return true;
    }
};
```
Unit testing is a misunderstood concept
Tags: programming, testing, beginners, tdd
Published: 2022-07-25 17:09:00

Here and there I come across complaints about "unit tests". Here are some examples:

❌"Unit tests are difficult to write"
✅(Yes, if the code base is in a bad shape and/or wasn't designed with a testability in mind)

❌"Unit tests are brittle"
✅(Yes, usually when you write tests for the sake of reaching some coverage goals)

❌"Unit tests are only testing technical implementation, not business value"
✅(Yes, if it the way you write you code under test)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1yn57jyqw6hwz1k5kmkd.jpeg)

I have a feeling that some people are too concerned with "what" and "how", while forgetting "why".

❓Why we write tests?
👉To confirm that the code that we intend to ship to the next stage isn't obviously and/or horribly broken

❓Why we could prefer smaller ("unit") tests?
👉They are faster (sometimes 600 times faster!)
👉They are more focused. They test smaller bits of business logic so if a test fails one usually would have a good idea of what might be wrong
👉While doing TDD we might be uncomfortable to focus on a complex behaviours without checking smaller behaviours first
👉They are working as forcing function. In my experience there's a strong positive correlation between how easy it is to write small tests (i.e. code testability) with the code readability and maintainability.

Does it make more sense now?
How to Change Place Order Button Text Based on Payment Gateways @ WooCommerce Checkout Page
Tags: wordpress, programming, tutorial, php
Published: 2022-07-25 17:08:00

Today, I will show you the easiest way to dynamically and conditionally Rename Place Order Button Text Based on Payment Gateways @ WooCommerce Checkout Page.

{% youtube s1-MYL75uPE %}

Download Source Code from Here:

[Source Code](https://wpcodersclub.com/woocommerce-rename-place-order-button-at-checkout/)
How to Make Money Programming
Tags: webdev, programming, beginners, tutorial
Published: 2022-07-25 16:55:59

They’re many ways to make money in this programming world and this is the easiest way.....

1. **Sell Softwares**

2. **Freelancing**

3. **Sell Courses**

4. **Sell Ebooks**

5. **Blogging**

6. **Youtube**

7. **Getting a Programming Job**

8. **Web/App Development**

9. **Game Development **
A welcome post
Published: 2022-07-25 16:54:00

It's my birthday today, so I feel like writing an introduction post for all my new followers here.

I'm Nadia, and this is what you should know about me:

🤖 I'm a self-taught software engineer, building chat bots at [Intercom](https://www.intercom.com/)
📖 I published a book about how anyone can become a programmer
👩‍💻 My goal is to help more non-STEM people enter tech

On my [LinkedIn](https://www.linkedin.com/in/beetlehope/), I talk about learning to code and building a career in tech.

If you are now learning to code, check out my [book](https://beetlehope.gumroad.com/l/fhIFH).

This book will be your personal mentor that will teach you everything you need to know to go from zero tech skills to being employed as a coder.

You might also want to check out my Youtube channel: https://www.youtube.com/c/beetlehope

I talk about:
✅ finding your first job in tech
✅ managing your career growth
✅ taking control of your mental health and productivity

Thanks for reading until the end ❤️

Feel free to introduce yourself down below 👇
Deploying React App to Netlify
Tags: javascript, webdev, beginners, tutorial
Published: 2022-07-25 16:52:05

A [react app](https://reactjs.org/docs/create-a-new-react-app.html) is a single page application which means that there's only one document i.e. `index.html` file which is updated by javascript as per the requirement of the user.

In this tutorial, I am going to show you how you can deploy a react app on [netlify](https://www.netlify.com/) from an existing `git` repository of yours.

## Tutorial

- Create a [`netlify.toml`](https://docs.netlify.com/configure-builds/file-based-configuration/#sample-netlify-toml-file) file at the rool of your react app and add the following rule to it.

```toml
[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200
```

> The above rule is applicable if you have multiple routes and have used libraries like `react-router` in your project.

Basically what we are doing here is we are telling netlify to redirect all the routes to our `index.html` file with a status code of 200 because our application is built with react and it is a [single page application](https://developer.mozilla.org/en-US/docs/Glossary/SPA). We already discussed what an SPA is at the very beginning of this tutorial.

- Set up an [account on netlify](https://app.netlify.com/) if you haven't already.
- Go to the `sites` tab and add a new site.

![add a new site](https://i.imgur.com/lxA2nQP.jpg)

- Select `import an existing project` from the dropdown menu.
- You will see a number of providers from which you can import your project.

![importing a project](https://i.imgur.com/5f7byCG.jpg)

- Authenticate and select a repository.
- Modify the default deployment configuration as per your requirement.

![deployment configuration](https://i.imgur.com/heodEQG.jpg)

- If required, you can also add `env` variables.
- Finally, click on `deploy site` and your site should be deployed.

That's all for now. Signing off.

> This post was originally published in [Syntackle](https://syntackle.live/blog/deploying-react-app-to-netlify-XZ_dWXAd/).
What can I do as my first complete individual project?
Published: 2022-07-25 16:35:00

Hi, avocados!!  👋😃 🥑

I'm begging for your help, today...

As I told you before, I am currently taking part in a fullstack development bootcamp. Most of the projects we are working on are team projects, but I should be thinking of an individual project to create using Java and VUE 💻

Do you have any suggestions?

As a teacher, I have always been interested in improving education resources for teachers, so my big-big project idea is a gamification-for-educators project, BUT I am still learning, so I wouldn't know how to do something related as a start point, or even if I am able to do it. I think I will have 3 weeks to develop my project but we will be learning the JAVA basics for the first week, so... WOW. 🤯🤯 I don't think I can. 

Do you have any idea of the kind of projects I could think of for this individual work?


#help #firstProject #VUE #JAVA
Is it useful to study JavaScript in India?
Tags: javascript, learning, india
Published: 2022-07-25 16:32:00

JavaScript is a programming language that enables you to create dynamically updating content, control multimedia, animate images, and much more. As a result, learning JavaScript has become increasingly popular in recent years.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9h5882pv2ngxeq6f00yo.png)
 
JavaScript learning might be worth it for you if want to work in web development or if you want to build your own website. Even if you don’t plan on becoming a web developer though, learning JavaScript can still be beneficial. For example, knowing how to program can help sharpen your logical thinking and problem-solving skills.

Read: [Why JavaScript is Important for Web Developers?
](https://staticsave.com/blog/importance-of-javascript-in-web-development)

So is learning JavaScript worth it in India? Absolutely! Here are three reasons why:

1. There is high demand for JavaScript developers in India.

According to the 2018 Developer Skills Report from HackerRank, Indian developers rank #4 in the world for their skills in Java (which includes JavaScript). This means that there is high demand for developers with these skillset In India.

2. You can earn a good salary as a JavaScript developer in India.

According to PayScale, the average salary for a JavaScript developer in India is Rs 4,71,293 per year. This is significantly higher than the average salary in India, which is Rs 2,80,000 per year.

3. JavaScript is a versatile language that can be used for more than just web development.

JavaScript is a versatile language that can be used for more than just web development. For example, you can also use JavaScript for game development, mobile app development, and server-side programming. This means that learning JavaScript can give you a versatile skillset that can be used in a variety of different fields.

Also Read: [Learning Javascript for Web Development](https://staticsave.com/blog/learning-javascript-for-web-development)
How To Create Collections In Shopify Store | How To Create Gift Cards In Shopify Store
Tags: javascript, beginners, news, shopify
Published: 2022-07-25 16:10:29

How To Create Collections In Shopify Store | How To Create Gift Cards In Shopify Store

Learn How To Create Shopify Store (Shopify Store Setup Tutorial), Learn in English. Create Shopify Store, and earn money from home. Shopify Store creation and setup process for beginners. If you want to start drop shipping, or if you have brand and want to sell online by having ecommerce website then you can use Shopify to sell products.  Watch the complete video and learn How To Create Collections and Gift Cards in Shopify Store.

Shopify is an online Ecommerce platform which allows users to create online store. Using Shopify you can sell digital products, physical products and can also start drop shipping business. Shopify is one of the biggest ecommerce platforms and it is used by biggest companies across the world.

In this video I have shown complete process to create Collections and to create Gift Cards in Shopify Store. This video is helpful for all the beginners and also to users who are already using Shopify but have lesser knowledge about Shopify.


[![How To Create Collections In Shopify Store | How To Create Gift Cards In Shopify Store](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/930uuts1vwcbt3bxweiy.png)](https://youtu.be/ftbOvuhQai4)