Skip to content

Instantly share code, notes, and snippets.

@Melizzo
Created February 21, 2020 18:05
Show Gist options
  • Save Melizzo/6011d717ac3880efbeaa8a42d099ffd6 to your computer and use it in GitHub Desktop.
Save Melizzo/6011d717ac3880efbeaa8a42d099ffd6 to your computer and use it in GitHub Desktop.
Problem Solving
#### What was the experience? How much time did you have? What problem did you tackle? How did you pair with your teammate?
We had 45 minutes to problem-solve:
`var sheep = [
true, true, true, false,
true, true, true, true,
true, false, true, false,
true, false, false, true,
true, true, true, true,
false, false, true, true
];
countSheep(sheep);
// => 17`
My teammate was very supportive and nonjudgemental. We both very much had a "let's try it!" attitude that served us well.
#### What was your process in solving(or not quite yet solving) this problem?
We first used the whiteboard to psuedocode what we wanted to achieve in plain english. We then talked about how we would
acheive the solution - ie using a for loop, and having an empty array. We also talked about having a counter to count
specific times the word true was used. We looked at the array prototypes that were on the wall (.shfit push, .concat.
.reverse, .pop, .splice, .slice, includes, .unshift, indexof) and started with .includes
#### What peices of your your process felt helpful? What pieces maybe led you down the wrong path and what did you learn
#### from that?
Collaboration is something that I work with. Asking questions, rubberducking, verifiation that there aren't any syntax
errors is very helpful. We googled MDN. We worked with index, that only returned a boolan; ie, true/false value, which
was a bit confusing, but then realising that we wanted numbers, not boolans as a return.
#### Was there a time you "thought you had it", but realized you didn't? What did you learn from that?
I don't think that I ever have it, so when I can get information to console.log, or have a correct function, it's
more-so surprising that I was able to make it work. It's always a nice confidence boost that I got a function to work.
#### What advice do you have for your futureself?
Keep plugging. Ask for help. REPEATITION is key. Get in there ok? Do it. Do coding challenges, keep doing them.
var trueSheep = [];
// function countSheep(animal) {
// for(var i = 0; i < animal.length; i++) {
// if(sheep[i] === true) {
// trueSheep.push(animal)
// }
// }
// return sheep.length
// }
function countSheep(animal) {
var trueSheep = 0;
for(var i = 0; i < animal.length; i++) {
if(animal[i] === true) {
trueSheep++
}
}
return trueSheep
}
countSheep(sheep)
var totalSheep = sheep.filter(uwe => {
// console.log(uwe === true)
return uwe === true
});
console.log(totalSheep.length)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment