Day 60: 10_binarySearch

Inseo Park·2021년 10월 16일
0

Path to Data Scientist

목록 보기
58/58
post-thumbnail

1. TIL (Today I Learned)

Today I had a pair programming scheduled in my to-do list but my pair had some work to do so I decided to go on with the sprint alone. It was basically about http and networking. What a client and server is and what is http's role in communication between client and server. In my understanding client is usually the front-end part which most users of a digital service uses to interact inside the service. When a user presses a button that leads to another page, the client sends a message in the form of http to the server and asks for information needed in order to show the page the user is wanting to reach into. But, it sounds simple but the rules and procedures to follow or simply the lanuage clients and servers uses to communicate is http and not only http because there are so many kinds of 'languages' a client and server can talk to. The API given is like the dictionary of the language such as http, https, etc.

Next, I gave myself a challenge to solve a toy problem given by codestates. The following algorithm code asked me to come up with a function that iterates through a given array (arr) and return the index of the array which the index is given as (target).

    const binarySearch = function (arr, target) {
      let left = 0
      let right = arr.length - 1;
      while (left <= right) { // this loop stops if left is larger than right. 
        let middle = parseInt((right + left) / 2) // the variable middle is representing the current index to look on. It is given such value to start with the middle index of the array to lessen time.
        if (arr[middle] === target) { // this loop also ends if target is matching with the arr[middle] of the array.
          return middle;
        }
        if (target < arr[middle]) { // if the variable 'middle' is larger than target it means the value we are finding for is in the left or smaller half of the array. Now we are going to loop again to look at the half of half we found.
          right = middle - 1 
        } else {
          left = middle + 1
        }
      }
      return -1 // the loop when broken without finding the target value of the array, the algorithm required us to return a -1.
    };

2. 3 Things to be Thankful for

  1. Thank God for bringing me back to you.
  2. Thank God for allowing me to pay for dinner.
  3. Thank God for keeping my family safe and giving me hope to pray to you.

3. Ideas and Things to Think About

  1. Basically I always fail to focus on each day and always dream about the future only. It's good to think about the future but what you do each day and choices you make each moment decides your future. That is what God told you few days ago. Focus and today and be grateful that God allowed you to go through the day safely. Don't take the day for granted.
profile
my journey to become a data scientist.

0개의 댓글