This is the first part of this question/answer series because the answer I came up with was very easy only because I was able to use methods to help me solve it quicker than I think they (a/A) wants. They didn't explicitly say it in this problem, but in previous challenges it said to refrain from using methods like .reverse, which I used here. SO because of that I'm going to show you my short code and talk about .sort, and then another day I'll post a longer more confusing answer that shows your know how to harness the power of loops and variables with the wrath of Aphrodites. Or something. Idfk.
The problem:
# Write a method that takes an array of numbers in. Your method should
# return the third greatest number in the array. You may assume that
# the array has at least three numbers in it.
My Solution:
SO. Let's talk about .sort! Here's my wacky explanation, but please avail yourself to some of the links at the end of this post.
.sort is an array method. It'll work beautifully on arrays containing words and will alphabetize it the way you would. However, it will not do that with numbers. the computer would consider 100 before 2 because 1 is less than 2. So when it comes to numbers, we use this comparison function that you see in there. return a-b; will sort your numbers from least to greatest, while return b-a will sort your numbers from greatest to least. To avoid saying the wrong thing and causing someone out there (even if it's me at a later date) a massive headache because what I said was gobbledegook, this is as far as I'll go.
Next we want to reverse the array, because when we do that we can easily pull out the third number which by then should be the third greatest!
Make sure to check out these links:
http://www.w3schools.com/jsref/jsref_sort.asp
http://www.javascriptkit.com/javatutors/arraysort.shtml
How would you solve this?!
Showing posts with label women who code. Show all posts
Showing posts with label women who code. Show all posts
Wednesday, September 28, 2016
a/A Practice Problem: Third Greatest pt.1
Labels:
app academy
,
asmarterwaytolearn
,
cleverett
,
code
,
coder
,
coder girl
,
coding
,
developer
,
learn to program
,
practice problems
,
programming
,
women who code
,
womenwhocode
Tuesday, September 27, 2016
a/A Practice Problem: Is Power of 2?
Truth be told: I definitely looked for help on this problem. And that's OK!! (At least I think it is.) Part of the whole teaching yourself how to code (or anything really!) is learning from others. That means looking at solutions and understanding how that person got there. Not copy-and-pasting their code into the answer box and saying "DONE!", but writing it out yourself, a hundred times if you have to. I looked at a/A's answer to this (in Ruby) and was able to translate it into a working JS program.
Here's the problem:
# Write a method that takes in a number and returns true if it is a
# power of 2. Otherwise, return false.
#
# You may want to use the `%` modulo operation. `5 % 2` returns the
# remainder when dividing 5 by 2; therefore, `5 % 2 == 1`. In the case
# of `6 % 2`, since 2 evenly divides 6 with no remainder, `6 % 2 == 0`.
My Solution
That first if statement, tells us what to reject right away -- if the number passed in isn't divisible by 2, then we know that two things: that it's definitely an odd number, and that it cannot be a power of 2.
The while loop portion was something I picked up from Codewars. Let me try to dissect and explain: The (!num) portion only, excluding the first exclamation mark, is basically saying num is false. The exclamation mark acts like negation (I think-- please feel free to correct me!). So the outer exclamation mark (!(!num)) is a double negative and is basically saying while num is true.
A while loop still needs the same components as a for-loop: the initiation (num), the condition(while num is true) and termination (num is false).
Here's the problem:
# Write a method that takes in a number and returns true if it is a
# power of 2. Otherwise, return false.
#
# You may want to use the `%` modulo operation. `5 % 2` returns the
# remainder when dividing 5 by 2; therefore, `5 % 2 == 1`. In the case
# of `6 % 2`, since 2 evenly divides 6 with no remainder, `6 % 2 == 0`.
My Solution
That first if statement, tells us what to reject right away -- if the number passed in isn't divisible by 2, then we know that two things: that it's definitely an odd number, and that it cannot be a power of 2.
The while loop portion was something I picked up from Codewars. Let me try to dissect and explain: The (!num) portion only, excluding the first exclamation mark, is basically saying num is false. The exclamation mark acts like negation (I think-- please feel free to correct me!). So the outer exclamation mark (!(!num)) is a double negative and is basically saying while num is true.
A while loop still needs the same components as a for-loop: the initiation (num), the condition(while num is true) and termination (num is false).
- The first if within the loop would break us out of the loop if and when num is equal to 1 (which would be our 2 to the 0 power case. If we get to this case, that means it is a power of 2 and we should return true, which the code states!
- The else if scenario checks if the remainder of num / 2 is equal to 0. If it is, divide it by 2 again.
- The last else case will handle the other cases and if the number hasn't passed the first two cases, it's not a power of two, so we should return false.
What do you think? How would you solve this problem?!
Labels:
a/A
,
app academy
,
asmarterwaytolearn
,
cleverett
,
coder
,
coder girl
,
codewars
,
coding
,
javascript
,
learn to program
,
practice problems
,
programming
,
ruby
,
women who code
,
womenwhocode
Saturday, August 27, 2016
More Free Resources
I recently got a hold of some questions asked by the schools I want to attend during their preliminary coding challenges. Let's just say some were very, very hard.
I did one set of problems for one school and felt great! I was able to answer all three with very little effort and time, which of course was a huge relief. However, on the other exam I was able to fully answer ONE out of FIVE. I was almost done with the second and was able to write some pseudo code for the third, but by the end of my time I barely understood what the last two were asking from me. It was a huge blow.
Since then I've been researching, practicing, learning everything. From refreshing on my basics from 'A Smarter Way to Learn Javascript', to exploring completely new topics that have helped me solve the problems that once bamboozled me.
All in all, things have been progressing over on my end and I hope they are on yours as well! Today I just have a couple more links I've found while trying to learn on my own.
funfunfunctions: This guy is a little goofy and he codes using ECMA6 which at times is a little confusing since I'm still learning vanilla javascript, but he explains things pretty well and hates fibonacci sequences more than I do (which I didn't think was possible). He has some great videos covering more "basics" of javascript that really help push your code to the next level.
Codesmith.io: Codesmith is a dev bootcamp based out of LA. I discovered them while doing some research on course report and found that they offer **FREE** workshops titled 'JS: The Hard Parts'.
It's an in-person workshop you can sign into and participate in via youtube. You can even pair-program with a virtual partner (for which I am currently taking applications). The workshops are held weekly on Thursday nights and really tackled some of the tough stuff these coding schools would like their applicants to be aware of.
That's all for now! Stay tuned for the debut of an awesome website the boy and I are working on :)
I did one set of problems for one school and felt great! I was able to answer all three with very little effort and time, which of course was a huge relief. However, on the other exam I was able to fully answer ONE out of FIVE. I was almost done with the second and was able to write some pseudo code for the third, but by the end of my time I barely understood what the last two were asking from me. It was a huge blow.
Since then I've been researching, practicing, learning everything. From refreshing on my basics from 'A Smarter Way to Learn Javascript', to exploring completely new topics that have helped me solve the problems that once bamboozled me.
All in all, things have been progressing over on my end and I hope they are on yours as well! Today I just have a couple more links I've found while trying to learn on my own.
funfunfunctions: This guy is a little goofy and he codes using ECMA6 which at times is a little confusing since I'm still learning vanilla javascript, but he explains things pretty well and hates fibonacci sequences more than I do (which I didn't think was possible). He has some great videos covering more "basics" of javascript that really help push your code to the next level.
Codesmith.io: Codesmith is a dev bootcamp based out of LA. I discovered them while doing some research on course report and found that they offer **FREE** workshops titled 'JS: The Hard Parts'.
It's an in-person workshop you can sign into and participate in via youtube. You can even pair-program with a virtual partner (for which I am currently taking applications). The workshops are held weekly on Thursday nights and really tackled some of the tough stuff these coding schools would like their applicants to be aware of.
That's all for now! Stay tuned for the debut of an awesome website the boy and I are working on :)
Labels:
cleverett
,
code
,
coder
,
coder girl
,
coding
,
developer
,
factorial
,
javascript
,
programming
,
women who code
,
womenwhocode
Thursday, June 9, 2016
Codewars as a Training Tool
In this post I wanted to stick up for CodeWars and help explain to the novice coder why this site is so fucking awesome.
First, a little backstory. My boyfriend and I are both just starting out in this whole programming world. He was the one who told me about it first and when I first went to the site, I could barely get past the mandatory (but simple) coding challenges you have to get right in order to gain access to the full site.
Fast forward to today and I am on the site at least once a day training. It has become the best learning tool for me thus far. It challenges me every day, reminding me why I like coding. My boyfriend on the other, while he can build out an entire rails app, absolutely hates the site. I think it's because he hasn't given it enough of a chance (which is true), but he says his learning style is different (which also is true). Either way, I happen to think that anyone who uses the system the right way will soon too become a true believer. So, herein this post I present to you my methodology to using the site so that even you can conquer and earn your honor.
1. Select your level.
On the left hand side you will find everything you need to make sure you are doing problems within your range. The levels are from easiest, 8, to hardest, 1. Truth be told, it's best to have gone through the basics so that you can attempt the problems, but even if you are going along as you learn you can customize which problems to do (see below). Start off with 8, and move at your own pace. Some of the problems within are going to be a lot more difficult than some of the others. But give yourself some patience and work through them, absorbing everything you can.
2. Select what areas you want to train.
Once you've selected which level you want to compete in, you can then choose problems that have been tagged with certain areas of concentration. On the left hand side, under Tags, you can select Arrays, Numbers, Bugs, Fundamentals, etc. When I was starting out I found that the best thing that helped me was completing level 8 "bug" problems. They re-familiarized me with syntax and some other basic concepts that helped me to solve some other problems without the worry of that. If you're working through the problems while trying to master one area of a certain language, this will be one of the best ways to use CodeWars to do just that.
3. Don't be ashamed to forfeit honor.
No one likes to lose, obviously. But sometimes, you need to suck it up. There are problems that for some reason will not pass the tests, but once you click submit will actually work. Save for these cases, if you can't figure out why something won't work, it might be time to just unlock the solutions to that problem. It could be something simple you overlooked, but if it's something you can't figure out on your own, unlock the solutions and see how other people solved it. Think of it as learning, not cheating if you happen to be so honorable.
4. Read other peoples' answers.
Whether I submitted my answer or forfeited honor, I always look at other peoples' answers. There will be things in there that look like straight up gibberish. Even when I finished my Javascript book, there were things I had never seen before. Methods that would produce the right code with a fraction of the lines. It was insane. But it's also insanely insightful. Whenever there's something I don't understand I look it up, and you can get the general idea of the way something works once you see it.
Going through the site without any sort of order can be pretty depressing as a noob. You can easily get that "omg-I'm-never-going-to-understand-this-and-I-better-get-back-to-my-dead-end-job" feeling, but I swear with time, patience and a little order CodeWars can and will open all sorts of doors.
Labels:
code
,
coder
,
coder girl
,
codewars
,
developer
,
full stack academy
,
javascript
,
learn to code
,
learn to program
,
practice
,
practice problems
,
women who code
,
womenwhocode
Wednesday, June 8, 2016
a/A Practice Problems: Nearby AZ
Practice Problem 8 of 21 and the first medium! It's exciting stuff happening 'round these parts. Without further adieu...
Check out past problems here:
Write a method that takes a string in and returns true if the letter "z" appears within three letters **after** an "a". You may assume that the string contains only lowercase letters.
This is a little trickier, but still employs the same methods and logic that we've already seen. A couple loops and if statements.
1. Declare our function with one parameter, string.
function nearbyAZ (string) {
}
}
2. I wanted to declare a variable, index1, that would hold the place of the position in which the letter "a" appears. This will be helpful later when determining if there's a "z" within the next three letters.
function nearbyAZ (string) {
var index1 = 0;
}
3. We want to loop through all the letters in order to see if there's an "a". The code block within the loop will be an if/else statement. If there's an "a", store it's index number in the variable, index1, and break out of the loop. Else, I want to increase index1 by one with each iteration of the loop. This way we will store the correct position number.
function nearbyAZ (string) {
var index1 = 0;
for (var i = 0; i < string.length; i++) {
if (string[i] === "a") {
index1 = i;
index1 = i;
break;
}
else {
index1++;
}
}
}
4. After the previous loop, I want another variable, index2, which will store the value of index1 + 1. This will be where our loop will start, and it should end at the third letter after the first a: index1 + 3.
function nearbyAZ (string) {
var index1 = 0;
for (var i = 0; i < string.length; i++) {
if (string[i] === "a") {
break;
}
else {
index1++;
}
}
var index2 = index1 + 1;
for (var j = index2; j <= index1 + 3; j++) {
}
}
5. Start the loop at index2 because we are only concerned with the first three letters after the letter "a". Likewise, we'll want to stop the loop once it reaches that third letter. An if statement is the last part required to return true or false if there's a "z".
function nearbyAZ (string) {
var index1 = 0;
for (var i = 0; i < string.length; i++) {
if (string[i] === "a") {
break;
}
else {
index1++;
}
}
var index2 = index1 + 1;
for (var j = index2; j <= index1 + 3; j++) {
if (string[j] === "z") {
return true;
}
}
return false;
}
Check out past problems here:
Labels:
app academy
,
asmarterwaytolearn
,
cleverett
,
coder
,
full stack academy
,
javascript
,
learn to code
,
learn to program
,
practice problems
,
programming
,
women who code
,
womenwhocode
Monday, June 6, 2016
a/A Practice Problems: Time Conversion
Back at it again today! My plan is to continue solving these practice problems till I feel that "Oh hell yes!" sense of accomplishment. Let's get on with it.
Your mission: Write a method that will take in a number of minutes and returns a string that formats the number into "hours:minutes"
In keeping with tradition, think about how to solve this problem before doing any actual coding. I promise it's easier than Phoebe trying to teach Joey guitar cords without a guitar. #friends
The problem is asking us to convert any number of minutes given into the hours:minutes format. In order to do this there will have to be some math involved. Maybe set an hour counter equal to 0 and every time there's at least 60 that counter should go up by one. There should conversely be another counter that starts with the number passed in and decreases by 60 each time. Then it's just an issue of formatting, concatenating variables with strings and whatnot.
1. Let's go ahead and define our function with one argument. It is already provided in Ruby, but for Javascript it would be:
2. I defined two new variables here: hours, which I set equal to 0, and min, which I set equal to the parameter, minutes. (This last step might be repetitive, but it was how I solved the problem and it worked so I'm keeping it for now.)
3. Every time min is greater than or equal to 60, I want hours to increase by 1 and I want min to decrease by 60. To do this, I used a while loop. Inside the while loop, I want it to do all the math I explained above. Remember to include the counter (i -= 60) or you'll find yourself in an infinite loop. The same three parts of a for-loop are contained in a while loop, just the formatting is different.
4. Almost done! Just need to handle some special cases-- when there is less than ten minutes, you want it to read "06" or "0-whatever" not just "6". The second case you want it to handle is when there are 0 minutes, you want it to say "00". Sounds like an if statement.
This problem sent me for a loop. Yes, pun intended. It literally sent me into an infinite loop multiple times. Despite having to come back to this problem on different days to give it another shot, that little victory kinda made it all worth it. It's a pretty awesome feeling of accomplishment figuring these challenges out, even if it may not be the most concise code or employ best practices.. I have to actually know how do it first, amirite? Here's to the small victories!
P.S. I move to New York in TEN DAYS. (!!!!!!!!!!!!!)
Check out past problems here:
Your mission: Write a method that will take in a number of minutes and returns a string that formats the number into "hours:minutes"
In keeping with tradition, think about how to solve this problem before doing any actual coding. I promise it's easier than Phoebe trying to teach Joey guitar cords without a guitar. #friends
The problem is asking us to convert any number of minutes given into the hours:minutes format. In order to do this there will have to be some math involved. Maybe set an hour counter equal to 0 and every time there's at least 60 that counter should go up by one. There should conversely be another counter that starts with the number passed in and decreases by 60 each time. Then it's just an issue of formatting, concatenating variables with strings and whatnot.
1. Let's go ahead and define our function with one argument. It is already provided in Ruby, but for Javascript it would be:
function time_conversion(minutes) {
}
}
2. I defined two new variables here: hours, which I set equal to 0, and min, which I set equal to the parameter, minutes. (This last step might be repetitive, but it was how I solved the problem and it worked so I'm keeping it for now.)
function time_conversion(minutes) {
var hours = 0;
var min = minutes;
}
var hours = 0;
var min = minutes;
}
3. Every time min is greater than or equal to 60, I want hours to increase by 1 and I want min to decrease by 60. To do this, I used a while loop. Inside the while loop, I want it to do all the math I explained above. Remember to include the counter (i -= 60) or you'll find yourself in an infinite loop. The same three parts of a for-loop are contained in a while loop, just the formatting is different.
function time_conversion(minutes) {
var hours = 0;
var min = minutes;
var i = min;
while (i >= 60)
hours++;
min -= 60;
i -= 60;
}
}
var hours = 0;
var min = minutes;
var i = min;
while (i >= 60)
hours++;
min -= 60;
i -= 60;
}
}
4. Almost done! Just need to handle some special cases-- when there is less than ten minutes, you want it to read "06" or "0-whatever" not just "6". The second case you want it to handle is when there are 0 minutes, you want it to say "00". Sounds like an if statement.
function time_conversion(minutes) {
var hours = 0;
var min = minutes;
var i = min;
while (i >= 60)
hours++;
min -= 60;
i -= 60;
}
if (min === 0) {
min = "00"
return hours + ":" + min;
}
else if (min < 10) {
min = "0" + min;
return hours + ":" + min;
}
else {
return hours + ":" + min;
}
}
var hours = 0;
var min = minutes;
var i = min;
while (i >= 60)
hours++;
min -= 60;
i -= 60;
}
if (min === 0) {
min = "00"
return hours + ":" + min;
}
else if (min < 10) {
min = "0" + min;
return hours + ":" + min;
}
else {
return hours + ":" + min;
}
}
This problem sent me for a loop. Yes, pun intended. It literally sent me into an infinite loop multiple times. Despite having to come back to this problem on different days to give it another shot, that little victory kinda made it all worth it. It's a pretty awesome feeling of accomplishment figuring these challenges out, even if it may not be the most concise code or employ best practices.. I have to actually know how do it first, amirite? Here's to the small victories!
P.S. I move to New York in TEN DAYS. (!!!!!!!!!!!!!)
Check out past problems here:
Labels:
a/A
,
app academy
,
asmarterwaytolearn
,
coder girl
,
javascript
,
learn to code
,
learn to program
,
mark meyers
,
program
,
women who code
Monday, May 30, 2016
a/A Practice Problems: Sum Nums
This one is pretty straight forward. The only thing to look out for: for loop starting with num and decreasing each time.
Problem: Write a method that takes in an integer 'num' and returns the sum of all integers between zero and num, up to and including num.
Game Plan:
Step 1:
Step 2:
Step 3:
Loop starts with num and stops when it is greater than 0, or 1.
Step 4:
You could also write sum = sum + i;
Step 5:
Check out past problems here:
Problem: Write a method that takes in an integer 'num' and returns the sum of all integers between zero and num, up to and including num.
Game Plan:
>> function takes in one parameter, num.
>> for loop to go through each number below (and including) num (i--).
>> declare variable and set it equal to 0, will hold value from each iteration of loop.
>> return total sum
>> for loop to go through each number below (and including) num (i--).
>> declare variable and set it equal to 0, will hold value from each iteration of loop.
>> return total sum
Step 1:
function sumNums(num) {
}
}
Step 2:
function sumNums(num) {
var sum = 0;
}
var sum = 0;
}
Step 3:
function sumNums(num) {
var sum = 0;
for (var i = num; i > 0; i--) {
}
}
var sum = 0;
for (var i = num; i > 0; i--) {
}
}
Loop starts with num and stops when it is greater than 0, or 1.
Step 4:
function sumNums(num) {
var sum = 0;
for (var i = num; i > 0; i--) {
sum += i;
}
}
var sum = 0;
for (var i = num; i > 0; i--) {
sum += i;
}
}
You could also write sum = sum + i;
Step 5:
function sumNums(num) {
var sum = 0;
for (var i = num; i > 0; i--) {
sum += i;
}
return sum;
}
var sum = 0;
for (var i = num; i > 0; i--) {
sum += i;
}
return sum;
}
Check out past problems here:
Labels:
a/A
,
app academy
,
code
,
developer
,
for loops
,
javascript
,
learn to code
,
practice
,
women who code
Subscribe to:
Posts
(
Atom
)


