Day #12: Greedy Algorithms, Memoization, & steps for Technical Communication



Subscribe to our newsletter

By subscribing, you agree with Revue’s Terms of Service and Privacy Policy and understand that #100 Days of Code will receive your email address.

Puppy Nomadic
Puppy Nomadic
Today, we continued with JS fundamentals, and Mike delivered a few lectures giving us the groundwork for peer programming and collaborative engineering at CodeSmith. It was inspiring to watch the Seniors present their Open Source Project ideas.
TOPICS: Greedy Algorithms, Object-Oriented Programming (prototypes, class, new keyword), Memoization, Deep Clone, Throttle

Greedy Algorithm
A greedy algorithm is an approach for solving a problem by selecting the best option available at the moment. It doesn’t worry whether the current best result will bring the overall optimal result. The algorithm never reverses the earlier decision even if the choice is wrong.
Neat code snippet by Mike using reduce and string interpellation for assigning a key to an object.
const singlesCount = dice.reduce((singlesCache, die) => {
if (!singlesCache[die]) singlesCache[die] = 1;
else singlesCache[die]++;
if (singlesCache[die] === 3) {
total += possiblePoints[`${die}${die}${die}`];
delete singlesCache[die]; }
return singlesCache;
Steps to Technical Communication
(Shared by Walter in Slack)
When setting up a basic JS whiteboard environment establish:
1. Global Execution Context
2. Define Global Memory (go through the code and setup your variables and what is stored with those labels)
3. Create the Call Stack
4. Establish the Thread Of Execution
5. If a JS function is being invoked you open a Local Execution Context.
5a. PUSH the function to the CALL STACK
5b. Establish the LOCAL MEMORY before executing code and pair your arguments with parameters.
5c. When the Local Execution Context (LEC) is completed that LEC is GARBAGE COLLECTED and the THREAD OF EXECUTION exits the LEC
5d. The function is POPPED from the CALL STACK
Great graphic from Aiden's Approach lecture today.
Great graphic from Aiden's Approach lecture today.
In computing, memoization or memoization is an optimization technique used primarily to speed up computer programs by storing the results of expensive function calls and returning the cached result when the same inputs occur again.
Making use of memoization can change a recursive problem like Fibonacci sequence from exponential time complexity to linear, by enabling us to use dynamic programming approaches.
Geeks for Geeks: Dynamic Programming
Geeks for Geeks: Dynamic Programming
Here's a great video on solving the fibonacci sequence problem using memoization and DP.
Here's a great video on solving the fibonacci sequence problem using memoization and DP.
In Javascript, memoization can be accomplished with the clever use of closure. Getting used to this syntax of returning a function within a function is critical.
Here’s Aiden’s example from class today:
function mo(func) {
const cache = {};
return (...args) => {
const key = JSON.stringify(args);
if (!Object.hasOwnKey(cache, key)) {
cache[key] = func(...args);
return cache[key];
To call it, I could do something like this:
function squareANumber(x) {
return x * x;
const moSquareANumber = mo(squareANumber);
const nine = moSquareANumber(3); // => 9
Did you enjoy this issue? Yes No
Puppy Nomadic
Puppy Nomadic @puppynomadic

Let's pull each other up by our Bootstrap.js 🪴 👩🏻‍💻 🦮

=== Journey of software craftsmanship ===

{"Formerly": ["nonprofit community organizer", "teacher", "researcher", "government director"],
"Future": ["software engineer", "web3 dev", "developer advocate", "technical program manager"]

In order to unsubscribe, click here.
If you were forwarded this newsletter and you like it, you can subscribe here.
Created with Revue by Twitter.