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
function* fibonacci() { | |
var earlierPrev = 0; | |
var prev = 0; | |
var index = -1; | |
while (true) { | |
index++; | |
if (index == 0) { | |
yield 0; | |
} else if (index == 1) { | |
prev = 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
function fibonacci(index) { | |
if (index == 0) { | |
return 0; | |
} else if (index == 1) { | |
return 1; | |
} else { | |
return fibonacci(index - 2) + | |
fibonacci(index - 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
rflect.ui.MomentumScroller.prototype.doMomentum = function() { | |
// Calculate the movement properties. Implement getEndVelocity using the | |
// start and end position / time. | |
var velocity = this.getEndVelocity(); | |
if (velocity != 0) { | |
var acceleration = this.getAcceleration(velocity); | |
var displacement = - (velocity * velocity) / (2 * acceleration); | |
var time = - velocity / acceleration; | |
var newY = this.contentOffsetY + displacement; |
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
rflect.ui.MomentumScroller.prototype.snapToBounds = function() { | |
const transition = rflect.browser.css.getSelectorCasedProperty('transform') + | |
' ' + 500 + 'ms ease-out'; | |
this.setTransitionAll(transition); | |
// Different out of bounds cases: | |
// 1. If content is lower than frame upper border | |
if (this.contentOffsetY > 0) { | |
this.contentOffsetY = 0; | |
rflect.browser.css.setTransform(this.getScrollBarContainer(), |
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
function bubbleSort(aInput) { | |
const output = [...aInput]; | |
for (let padding = 0; padding < output.length; padding++) { | |
for (let counter = 1; counter < output.length - padding; counter++){ | |
const prev = output[counter - 1]; | |
const next = output[counter]; | |
if (prev > next) { | |
swap(output, counter - 1, counter); | |
} | |
} |
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
function selectionSort(aInput) { | |
const output = [...aInput]; | |
for (let padding = 0; padding < output.length; padding++) { | |
let minimal = output[padding]; | |
let minimalIndex = padding; | |
for (let counter = padding + 1; counter < output.length; counter++) { | |
if (output[counter] < minimal) { | |
minimal = output[counter]; | |
minimalIndex = counter; | |
} |
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
function insertionSort(aInput) { | |
const output = [...aInput]; | |
let lastSortedIndex = 0; | |
for (let counter = 1; counter < output.length; counter++) { | |
const itemInQuestion = output[counter]; | |
let newIndexToPlace = counter; | |
for (let sortedIndex = counter - 1; sortedIndex >= 0; sortedIndex--) { | |
if (itemInQuestion < output[sortedIndex]) { | |
output[sortedIndex + 1] = output[sortedIndex]; |
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
function mergeSort(aInput) { | |
if (aInput.length == 0 || aInput.length == 1) { | |
return [...aInput]; | |
} else { | |
const middleIndex = Math.floor(aInput.length / 2); | |
return merge(mergeSort(aInput.slice(0, middleIndex)), | |
mergeSort(aInput.slice(middleIndex))); | |
} | |
} |
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
function quickSort(aInput, aLeftIndex, aRightIndex) { | |
if (aInput.length > 1) { | |
const delimeter = partition(aInput, aLeftIndex, aRightIndex); | |
if (aLeftIndex < delimeter - 1) { | |
quickSort(aInput, aLeftIndex, delimeter - 1); | |
} | |
if (delimeter < aRightIndex) { | |
quickSort(aInput, delimeter, aRightIndex); | |
} | |
} |
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 Token = { | |
NUMBER: 1, | |
LEFT_PAREN: 2, | |
RIGHT_PAREN: 3, | |
PLUS: 4, | |
MINUS: 5, | |
DIVIDE: 6, | |
MULTIPLY: 7 | |
} |
OlderNewer