This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const combineReducers = reducers => (state = {}, action) => | |
Object.keys(reducers).reduce((acc, key) => ({ | |
...acc, | |
[key]: reducers[key](state[key], action) | |
}), {}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sum = ([x, ...xs]) => ( | |
xs.length === 0 | |
? x | |
: x + sum(xs) | |
); | |
console.log(sum([2, 4, 6])); // 12 | |
const count = ([x, ...xs]) => ( | |
xs.length === 0 | |
? 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const LinkedList = () => { | |
let length = 0; | |
let headNode = null; | |
let Node = (element) => ({ | |
element, | |
next: null, | |
}); | |
let size = () => length; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const xl = require('excel4node'); | |
const app = express(); | |
const makeReport = (request, response) => { | |
const wb = new xl.Workbook(); | |
const ws = wb.addWorksheet('Ödenmiş Mesai Raporu'); | |
// Create a reusable style |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// reverse a string using stack data structure | |
const reverse = s => { | |
let stack = []; | |
let reversed = ''; | |
// push all characters of string to stack | |
for (var i = 0; i < s.length; i++) { | |
stack.push(s[i]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const isOpening = (s, m) => m[s]; | |
const isClosing = (s, m) => ( | |
Object.values(m).includes(s) | |
); | |
const isValid = (last, s, m) => ( | |
m[last] !== s | |
); | |
const balancedParens = s => { | |
const mapping = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Complexity Analysis | |
* push: O(1) | |
* pop: Amortized O(1), Worst-case O(n) | |
* empty: O(1) | |
* peek: O(1) | |
*/ | |
function Queue() { | |
var stack1 = []; | |
var stack2 = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Child extends React.Component { | |
greeting() { | |
return 'hello world'; | |
} | |
} | |
class Parent extends React.Component { | |
render() { | |
return ( | |
<TheChild ref='foo' /> | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getCachedExpensiveComputation() { | |
if (this._cachedSomeProp !== this.prop.someProp) { | |
this._cachedSomeProp = this.prop.someProp; | |
this._cachedComputation = doExpensiveComputation(this.prop.someProp); | |
} | |
return this._cachedComputation; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
<CustomList items={this.props.items} /> | |
<ComplexForm props={this.props.complexFormProps} /> | |
</div> |