Skip to content

Instantly share code, notes, and snippets.

/*
*
*
* This code was written specifically for a CodeWars kata, and is different than the code
* we worked through in class because it is designed for a different purpose.
* It shows that there is not one right way to break things into classes/objects (or functions)
* it depends on what your goals are and what you need it to do!
*
* Also, this isn't doctrine on how to solve this problem,
class AcceptedAnswerPrompt {
constructor(acceptedAnswers, ignoreCapitalization) {
this.acceptedAnswers = acceptedAnswers;
this.ignoreCapitalization = ignoreCapitalization;
}
checkIfAccepted(answer) {
// return true if it's in the list, false if it's not
for(const acceptedAnswer of this.acceptedAnswers) {
// The same thing as the other one, I just changed the syntax of the first two lines to ES6 Classes, if that makes it clearer
class List {
countSpecDigits(integersList, digitsList){
// keep a tally of the digits that I see that I'm supposed to count
const tallyList = digitsList.map(number => [number, 0]);
// loop over the list of integers
for(const integer of integersList) {
const integerDigitList = String(integer).split("").map(Number);
for(const digit of integerDigitList) {
body {
margin: 0;
padding: 0;
font-family: Arial, Helvetica, sans-serif;
}
/***** Navbar *****/
.navbar {
class AcceptedAnswerPrompt {
constructor(acceptedAnswers, ignoreCapitalization) {
this.acceptedAnswers = acceptedAnswers;
this.ignoreCapitalization = ignoreCapitalization;
}
checkIfAccepted(answer) {
// return true if it's in the list, false if it's not
for(const acceptedAnswer of this.acceptedAnswers) {
class AddressBook {
constructor() {
this.entries = [];
}
// get all your entries
getAll() {
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Some Page</title>
</head>
<body>
<nav>
<h1>Chairs</h1>
<ul>
// Normal function
function isNotEmpty(paper) {
return paper !== "";
}
// Arrow function
const isNotEmpty = (paper) => {
return paper !== "";
}
class AcceptedAnswerPrompt {
constructor(acceptedAnswers) {
this.acceptedAnswers = acceptedAnswers;
}
checkIfAccepted(answer) {
// return true if it is in the list of accepted answer
for(const acceptedAnswer of this.acceptedAnswers) {
if(acceptedAnswer === answer) {
// Cooks in pressure cooker
function cookInPressureCooker(howLong, food) { // var howLong = 20; var food = "chicken"
return food + " cooked for " + 20 + " minutes";
}
function makeDinner() {
var chicken = "chicken";
var soup = "soup";
chicken = cookInPressureCooker(20, "chicken");