Getting Ready for Hack Reactor

I start Hack Reactor on August 14th. I’m so pumped to learn Full-Stack JavaScript with some seriously smart people. HR appealed to me the most in terms of Software Engineering Accelerators because of the curriculum and their selectivity — I know that I’ll be pushed to my limits by the instructors and my peers 😃

I spent the day unwinding after a long month of prework and various personal commitments. Prework was from mid June to August. The prework was tough but also lots of fun! 😃 We did things like rebuild parts of underscore & jquery from scratch, with lots of emphasis on functional programming and recursion. We also honed our front end dev chops by building a twitter clone.

I’m taking the Coursera Algorithms course offered by Princeton, and last week Binary Search was on the curriculum, so I practiced implementing it. The iterative version is easy enough, so I thought to try it out recursively to get some more recursion practice. I did two versions, one where a ‘low’ index and a ‘high’ index were parameters, and another where they weren’t. Here’s that latter version below.

This function searches an array for a target value, and if it’s present, it returns the index of the target value. If it’s not present, it returns -1.

Binary Search:

function binarySearchRecursive2(arr, target) {  
function search(lo, hi) {
if (lo > hi) {
return -1
var mid = Math.floor((lo + hi) / 2);
if (arr[mid] < target) {
return search(mid + 1, hi);
} else if (arr[mid] > target) {
return search(lo, mid - 1);
} else {
//this deals with arr[mid] and the target being equal. if they are, return that index.
return mid;
//this is where lo and hi get set:
return search(0, arr.length-1);
var hello = [3, 5, 6, 7, 8, 12, 14, 15, 16, 17, 18, 20, 27, 31, 33, 35, 41, 45, 51, 56, 65, 67, 77, 78, 88, 89, 90, 100];  
console.log(binarySearchRecursive2(hello, 66)); //returns -1
console.log(binarySearchRecursive2(hello, 6)); //returns 2

Thoughts/comments? Feel free to hit me up. Other than that, I’m just getting ready for the move across the country. Super excited to attend Hack Reactor!

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.