This file contains hidden or 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
export default function findAmountOfSmallestUnitLengthClosedIntervals(sortedPoints) { | |
if(sortedPoints.length <= 1) return 1; | |
let amount = 0; | |
for (let i = 0, len = sortedPoints.length - 1; i < len;) { | |
let unitClosed = false; | |
for (let z = i + 1; z < sortedPoints.length; z++) { | |
if (sortedPoints[z] - sortedPoints[i] < 1) { | |
unitClosed = true; | |
if (z === sortedPoints.length - 1) { |
This file contains hidden or 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 findMetrics(values) { | |
return Math.hypot(...values); | |
} | |
export function updateWithMetrics(usersVotes) { | |
if (obj(usersVotes).doesntExist()) return null; | |
for (let i = 0, len = usersVotes.length; i < len; i++) { | |
const currentUser = usersVotes[i]; |
This file contains hidden or 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
export default function generator() { | |
const valuesToReturn = generator.prototype.valuesToReturn; | |
return { | |
value: null, | |
done: null, | |
next() { | |
const returnThis = valuesToReturn.pop(); | |
return { | |
value: returnThis, |
This file contains hidden or 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
/** | |
* This function uses dijkstra algorithm to find the shortest way in graph. | |
* So for this function to work properly, graph must be directed and acyclic with positive weights only | |
*/ | |
export default function findShortestWayIn(graph) { | |
const minimumCosts = {}; | |
let queue = [{}]; | |
const visitedPointsFromSpecificParent = {}; // to detect a cycle in a graph | |
return { |
This file contains hidden or 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 ifThereIsRouteFrom(start) { | |
const queue = [start]; | |
return { | |
to(finish) { | |
currentCity = queue.shift(); | |
if (typeof currentCity === "undefined") return false; | |
for (let i = 0, len = currentCity.length; i < len; i++) { | |
if (currentCity[i]['name'] === finish) return true; | |
queue.push(currentCity[i]); | |
} |
This file contains hidden or 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 forwardTrace(lcsMatrix, set1, set2) { | |
for (let rowIndex = 1; rowIndex <= set2.length; rowIndex += 1) { | |
for (let columnIndex = 1; columnIndex <= set1.length; columnIndex += 1) { | |
if (set1[columnIndex - 1] === set2[rowIndex - 1]) { | |
lcsMatrix[rowIndex][columnIndex] = lcsMatrix[rowIndex - 1][columnIndex - 1] + 1; | |
} else { | |
lcsMatrix[rowIndex][columnIndex] = Math.max( | |
lcsMatrix[rowIndex - 1][columnIndex], | |
lcsMatrix[rowIndex][columnIndex - 1], | |
); |
This file contains hidden or 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 fib(pos, fibValues) { | |
if (typeof fibValues[pos] !== "undefined") { | |
return fibValues[pos]; | |
} | |
result = fib(pos - 1, fibValues) + fib(pos - 2, fibValues); | |
fibValues[pos] = result; | |
return result; | |
} |
This file contains hidden or 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
// This is how tree should look like | |
// const tree = { | |
// root: { | |
// left: { | |
// left: { | |
// left: null, | |
// right: null, | |
// value: 3 | |
// }, | |
// right: { |
This file contains hidden or 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
let insertionSort = (inputArr) => { | |
let length = inputArr.length; | |
for (let i = 1; i < length; i++) { | |
let key = inputArr[i]; | |
let j = i - 1; | |
while (j >= 0 && inputArr[j] > key) { | |
inputArr[j + 1] = inputArr[j]; | |
j = j - 1; | |
} | |
inputArr[j + 1] = key; |
This file contains hidden or 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 arrayConcatenating(...arrs) { | |
let newArr = []; | |
for (let i = 0; i < arrs.length; i++) { | |
newArr = newArr.concat(arrs[i]); | |
} | |
return newArr; | |
} |