Skip to content

Instantly share code, notes, and snippets.

@dfernandeza
dfernandeza / grokking_to_leetcode.md
Created June 20, 2022 10:34 — forked from tykurtz/grokking_to_leetcode.md
Grokking the coding interview equivalent leetcode problems

GROKKING NOTES

I liked the way Grokking the coding interview organized problems into learnable patterns. However, the course is expensive and the majority of the time the problems are copy-pasted from leetcode. As the explanations on leetcode are usually just as good, the course really boils down to being a glorified curated list of leetcode problems.

So below I made a list of leetcode problems that are as close to grokking problems as possible.

Pattern: Sliding Window

@dfernandeza
dfernandeza / flatten.js
Last active April 18, 2018 11:10
Flatten an array of arbitrarily nested arrays of integers into a flat array of integers
let arr = [[1, 2, [3]], 4];
let flatten = a => a.reduce((acc, v) => Array.isArray(v) ? [...acc, ...flatten(v)] : [...acc, v], []);
console.log(flatten(arr)); // [1, 2, 3, 4]
@dfernandeza
dfernandeza / hyper-simple-module-system.js
Created June 27, 2016 20:17
Hyper Simple JS Module System
// module-system.js
(function (global) {
var APP = Object.create(null);
function module(path) {
var modules = path.split('.');
return modules.reduce(function(root, module) {
if (!root[module]) {
root[module] = Object.create(null);
@dfernandeza
dfernandeza / searchBox.js
Created June 14, 2016 21:20
SearchBox React component
import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import { searchCharacter } from '../actions';
const SearchInput = ({ query, onSearch }) => (
<form action="#">
<div className="mdl-textfield mdl-js-textfield">
<input
className="mdl-textfield__input"
<dom-module id="my-component">
<link rel="import" type="css" href="my-component.css">
<template>
<h1>My first Polymer component</h1>
</template>
<script> Polymer({ is: 'my-component' }); </script>
</dom-module>
var MyComponent = React.createClass({
render: function() {
return ( <h1>My first React component</h1> );
}
});
import {Component, View, bootstrap} from 'angular2/angular2';
@Component({ selector: 'my-component' })
@View({ template: '<h1>My first Angular 2 component</h1>' })
class MyComponent {}
bootstrap(MyComponent);
<section ng-controller=”productList”>
<ul>
<li ng-repeat=”prod in products”>{{ prod.name }}</li>
</ul>
</section>
<!-- antipattern: DO NOT DO THIS! -->
<textarea name="message">Hello world!</textarea>
<!-- DO THIS INSTEAD -->
<textarea name="message" value="Hello world!" />
React.createClass({
// Extract the values from the checked checkboxes
_extractValues: function() {
var values = this.getDOMNode().querySelectorAll('input:checked');
values = Array.prototype.slice.call(values);
values = values.map(function(c) {
return c.value;
});
return values.join(',');