Posts

Showing posts from March, 2018

JavaScript Feature - Client-Side Interactivity

Image
Welcome back, friends! My previous posts have covered the origins of JavaScript and the basics of the language. As we've discussed, JavaScript works hand-in-hand with HTML and CSS to create dynamic, interactive websites. While HTML delivers the content and CSS delivers the styling JavaScript interacts with the user. The benefit of JS is that it can perform its tasks without calling back to the server. Thinking of the work we did in VisualStudio, the UI was created with HTML and CSS and every time a control was clicked, it caused a post-back to the server in order to access the functionality. This is what sets JS apart from other languages. It can perform tasks without the post-back. It transforms a static page into something much more interesting, and because all modern web browsers are already compatible with JS, there are no plugins required to run scripts. Because JavaScript is such a popular language, it has a ton of libraries and frameworks available to extend its capabili...

Binary Search in JavaScript

Image
In this week's JavaScript lesson we're going to look at how to create a Binary Search function. What is Binary Search? Binary search is an algorithm that locates the index of a value in a sorted list, like an array. It accomplishes this task by splitting the list in half and comparing the value at the mid-point index to the search value. If a match is found, the mid-point index is returned. If the value is not located in the middle position of the list, the middle position becomes the new start or end for the search, based on if the search value is higher or lower than the value stored in the middle index. If the search value is higher, the mid-point index becomes the new start index. If it is lower, it becomes the end index. The search continues, looping until the search value is found in the list. If the search value is not found, a statement indicating this is returned. Binary Search Syntax In JS, we define a function (binarySearch) that takes a list and valu...