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 mmInOneInch = 25.4; | |
const mockRpm = 3000; | |
const tyreWidthInMm = 225; | |
const tyreHeightInPercentage = 45; | |
const tyreRimHeightInInch = 17; | |
const finalRatio = 3.38; | |
const someRevs = [2000, 2500, 3000, 4500, 5000, 5500]; |
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
let list = [1,2,3,4]; | |
let forEachCalled = 0; | |
list.forEach(item => { | |
// this one does something for every item in the array | |
// and returns the original array | |
forEachCalled++; | |
}); | |
const mapped = list.map(item => { |
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
async function waitForStuff(i) { | |
return new Promise((resolve) => { | |
setTimeout(() => resolve(`yay!`), 100) | |
}) | |
} | |
async function main() { | |
const mapped = Promise.all([1,2,3,4].map(async (item) => { | |
const res = await waitForStuff() | |
return res |
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 input = [ | |
[ 1, 2, 3 ], | |
[ 4, 5 ], | |
[ 6, 7, 8, 9 ], | |
[ 10 ], | |
[ 11, 12 ], | |
[ 13, 14, 15, 16, 17 ] | |
] | |
const outputLimit = 12 | |
const chunkLimit = 2 |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<style> | |
body { | |
font-family: sans-serif; | |
} | |
.results-wrapper { | |
height: 200px; | |
width: 300px; |
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
try { | |
let obj = {a: 0} | |
let a = obj | |
[0,1,2].forEach(item => console.log(item)) | |
} catch (e) { | |
console.log('First scenario', e) // throws TypeError: Cannot read property 'forEach' of undefined | |
} | |
try { |
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 getFilesInDirSync(pathToDir, files = []) { | |
const dirContents = fs.readdirSync(pathToDir); | |
return files.concat(dirContents.map(item => { | |
const isDir = fs.statSync(pathToDir + item).isDirectory() | |
return isDir ? getFilesInDirSync(`${pathToDir}/{item}`, files) : [`${pathToDir}/{item}`] | |
})) | |
}) |
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 PAIR_MATCHER = /([A-Z]?)([^A-Za-z,]+),(.*)/ | |
function moveSvg(path, x=0, y=0) { | |
return path.split(' ').map(pair => { | |
const matches = pair.match(PAIR_MATCHER) | |
return matches === null ? | |
pair : | |
`${matches[1]}${parseFloat(matches[2]) + x},${parseFloat(matches[3]) + y}` | |
}).join(' ') | |
} |
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
<html> | |
<head> | |
<style> | |
.wrapper { | |
background: red; | |
position: relative; | |
margin: 100px; | |
width:100px; | |
height: 100px; | |
} |
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 fibonacci = (limit, list=[1, 1]) => { | |
const currentIndex = list.length - 1 | |
const newNumber = list[currentIndex - 1] + list[currentIndex] | |
if( newNumber >= limit) { | |
return list | |
} else { | |
return fibonacci(limit, list.concat([newNumber]), currentIndex + 1) | |
} | |
} |
NewerOlder