Tech assessment challenges

Post Flatiron, I’ve been deep into my job search and trying to learn different technologies. On the coding side of things, most of my focus lately has been on getting a few of my projects launched on the web and making small practice apps that implement something I’ve been wanting to learn. This past week, I was fortunate enough to get a few positive responses lately from very good companies. I had a few days to log into a system and complete a technical assessment. Unfortunately, I didn’t do that great, but I did learn a super valuable lesson, KEEP PRACTICING THOSE ALGORITHMS!!! I feel like I’ve spread myself a bit thin and have neglected one of my favorite parts of coding, problem solving. I used to spend solid time on codewars.com and am definitely adding it back into my daily routine. In this week’s blog I’m going to cap off my sermon on why it’s important to practice code challenges by walking through one here!

***Example question from Hackerrank(https://www.hackerrank.com/challenges/camelcase/problem) ***

There is a sequence of words in CamelCase as a string of letters, , having the following properties:

  • It is a concatenation of one or more words consisting of English letters.
  • All letters in the first word are lowercase.
  • For each of the subsequent words, the first letter is uppercase and rest of the letters are lowercase.

Given , determine the number of words in .

Example

There are words in the string: ‘one’, ‘Two’, ‘Three’.

Function Description

Complete the camelcase function in the editor below.

camelcase has the following parameter(s):

  • string s: the string to analyze

Returns

  • int: the number of words in

Input Format

A single line containing string .

Constraints

Sample Input

saveChangesInTheEditor

Sample Output

5

Use the link above to follow along on HackerRank!

The first thing I like to do after reading the question/problem is to console.log to get a feel for exactly what is coming through as the input.

function camelcase(s){
console.log(s)
}

when we do that, we see our debug output is ‘saveChangesInTheEditor’.

So the first thing I wanted to do with the input was split it into an array so we can loop over each letter.

function camelcase(s){
let arr = s.split('')
console.log(arr)
}

I like to console log as often as I can to make sure I have an understanding of exactly what I’m working with.

So at this point we have an array of each individual letter. This problem isn’t too complicated and just want the number of words in the input string. To do this we can count how many of the letters are capitalized since every word other than the first word in camel case will be capitalized. If we make a count variable that starts at 1 (there were no tricky test cases with empty arrays or strings) and increment it by 1 for each capital letter we’ll have our count!

function camelcase(s){
let arr = s.split('')
let count = 1
arr.forEach(l => l == l.toUpperCase() : count += 1 : null)
return count
}

And there we have it, our test passes! It’s important to stay sharp on problems like these. When you open a lot of those coding assesments, the clock is ticking and you only get one shot! Take it from me, it’s really no fun at all when you bomb an assessment 😥.