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.
};