Haskell | TypeScript | Notes |
---|---|---|
2 /= 2 |
2 != 2 |
|
conanO'Brien = "It's a-me, Conan O'Brien!" |
const conanOBrien = "It's a-me, Conan O'Brien!" |
Called definitions or names in Haskell when fn has no params. Interchangable with the primitive value |
doubleUs x y = doubleMe x + doubleMe y |
const doubleUs(x, y) => doubleMe(x) + doubleMe(y) |
|
`doubleSmallNumber x = if x > 100 the |
Array.prototype.sayHello = () => console.log('Hi there!')
[].sayHello()
[1, 2, 3, 4, 5].sayHello()
And if you really want a negative stance on your code review
Array.prototype.peteAndRepeat = function(){this.forEach(val => console.log(`Pete says ${val}`))}
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 state = { test: 3, hello: 399, testinghhhh: 1 }; | |
const stateWords = Object.keys(state); | |
const stateNumbers = Object.values(state); | |
const itemStr = 'Item'; | |
const countStr = 'Count'; | |
let longestWord = itemStr.length; | |
let longestNumber = countStr.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
Array.prototype.filter = function (callback) { | |
const arr = this; | |
const returnedVal = []; | |
for (const i = 0; i < arr.length; i++) { | |
const exist = callback(arr[i], i, arr); | |
if (exist) { | |
returnedVal.push(arr[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 mm = require('music-metadata'); | |
const fs = require('fs'); | |
const files = fs.readFileSync('../New\ playlist.m3u').toString().split("\r\n"); | |
let songs; | |
songsP = Promise.all(files.map(file =>mm.parseFile(file).then(v => ({...v, fileName: file})).catch(a => null))) | |
songsP.then(val => songs = val) | |
// make sure there are really duplicates in the list | |
songs = songs.filter(song => !!song).filter(song => song && songs.find(sonn => (song.common.title == sonn.common.title) && (song.fileName != sonn.fileName))) |
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
// Say you have an Iterable that you want to turn into an array | |
const map = new Map() | |
map.set('a', 1); | |
map.set('b', 2); | |
// Array.from has you covered! | |
const twoDArr = Array.from(map); // [['a', 1], ['b', 2]] | |
// Not only can Array.from handle Maps, it can create brand new arrays | |
const emptyArr = Array.from({length: 3}); // [blank, blank, blank]; |
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
// This is a simple promise that will return a promise that resolves after the num | |
const getPromiseTimeout = num => new Promise(resolve => { | |
setTimeout(() => resolve(num), num); | |
}) | |
const timeouts = [getPromiseTimeout(100), getPromiseTimeout(300), getPromiseTimeout(200)]; | |
// Promise.all will run these promises in whatever order it wants, but will resolve | |
// with the same order they were passed in on. They run in 'parallel' | |
// Will console.log(100, 300, 200) in the same order as the order above |
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
# I use a community "Material Palenight" theme. I've found it has a color pallete I like a lot more for code: | |
# https://marketplace.visualstudio.com/items?itemName=whizkydee.material-palenight-theme | |
# I also use the "Material Design Icons Palenight" | |
# https://marketplace.visualstudio.com/items?itemName=Equinusocio.vsc-material-theme-icons | |
# I use a lot of extensions. Here's a list of all of them: | |
code --install-extension Angular.ng-template | |
code --install-extension attilabuti.vscode-mjml | |
code --install-extension auchenberg.vscode-browser-preview | |
code --install-extension christian-kohler.npm-intellisense |
- Does not support nested functions
- Must use variable/lambda assignment:
func main() {
test := func() {
println("Hello")
}
test()
https://github.com/donbright/rust-lang-cheat-sheet
→
=== return type info
// Function "main" returns unsigned int
fn main() -> u8 {
return 10;
}