Skip to content

Instantly share code, notes, and snippets.

// Here's another solution I made previously using some fancy reduce stuff to make me look cool
// https://www.codewars.com/kata/576bb71bbbcf0951d5000044/train/javascript
function countPositivesSumNegatives(input) {
if(!input || input.length === 0) return [];
return input.reduce(
(result, num) => (num > 0) ? [++result[0], result[1]] : [result[0], result[1] + num],
[0, 0]
)
}
// Racing
function startRiggedRace(riggedWinner, riggedLoser) {
var racers = [riggedWinner];
// Other ways we could add the rigged Winner
//racers.splice(0, 0, riggedWinner);
//racers.unshift(riggedWinner);
//racers.push(riggedWinner);
import React from 'react';
import { PropTypes } from 'prop-types';
import { useSelector } from 'react-redux';
/**
* Shows a category name and the number of transactions in that category
* Expects to go inside a <ul> with the class "list-group"
*
* @component
* @example
body {
margin: 0;
background-color: #fafafa;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
.button {
border: 0;
padding: 15px;
background-color: lightgray;
// https://www.codewars.com/kata/59de469cfc3c492da80000c5/train/javascript
function compress(sentence) {
// Get all the words lower case in an array
const words = sentence.split(" ").map(word => word.toLowerCase());
// Get rid of all the duplicates
const uniqueWords = words.filter( (word, index) => words.indexOf(word) === index );
// Make a string of the position of each word in the non-duplicates array
return words.map(word => uniqueWords.indexOf(word)).join("");
}
import React from 'react'
export default function CategoryFilter() {
return (
<div style={{ border: "1px solid black", padding: "15px", margin: "15px" }}>
<h3>CategoryFilter Component</h3>
<button>Tell TransactionFilters I'm Set</button>
<button>Tell TransactionFilters I'm Cleared</button>
</div>
)
const emailList = [
{
id: 234,
author: {
firstName: "Natalie",
lastName: "Childs"
},
to: "Calvin",
message: "Heyyyy",
read: false,
.bg-slate {
background-color: #4F5D61;
}
// https://www.codewars.com/kata/515bb423de843ea99400000a/train/javascript
// The constructor takes in an array of items and a integer indicating how many
// items fit within a single page
class PaginationHelper {
constructor(collection, itemsPerPage) {
this.collection = collection;
this.itemsPerPage = itemsPerPage;
}
class AcceptedAnswerPrompt {
constructor(acceptedAnswers) {
this.acceptedAnswers = acceptedAnswers;
}
// Returns true or false depending on if it's in the list or not
isAcceptedAnswer(potentialAnswer) {
return this.acceptedAnswers.includes(potentialAnswer);
}