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 capitalize(str) { | |
const capitalizedSentence = []; | |
for (let word of str.split(' ')) { | |
const capitalizedWord = word[0].toUpperCase() + word.slice(1); | |
capitalizedSentence.push(capitalizedWord); | |
} | |
return capitalizedSentence.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
// --- Examples | |
// steps(2) | |
// '# ' | |
// '##' | |
// steps(3) | |
// '# ' | |
// '## ' | |
// '###' | |
// steps(4) | |
// '# ' |
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
// --- Examples | |
// pyramid(1) | |
// '#' | |
// pyramid(2) | |
// ' # ' | |
// '###' | |
// pyramid(3) | |
// ' # ' | |
// ' ### ' | |
// '#####' |
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 vowels(str) { | |
const vowels = /[aeiou]/gi; | |
return str.split('').filter(char => char.match(vowels)).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
// --- Examples | |
// matrix(2) | |
// [[1, 2], | |
// [4, 3]] | |
// matrix(3) | |
// [[1, 2, 3], | |
// [8, 9, 4], | |
// [7, 6, 5]] | |
// matrix(4) | |
// [[1, 2, 3, 4], |
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
// Memoize to make more performant | |
function memoize(func) { | |
const cache = {}; | |
return function(...args) { | |
if (cache[args]) return cache[args]; | |
const result = func.apply(this, args); | |
cache[args] = result; | |
return result; | |
}; | |
} |
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 Queue { | |
constructor() { | |
this.data = []; | |
} | |
add(n) { | |
this.data.unshift(n); | |
} | |
remove() { | |
return this.data.pop(); | |
} |
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
interface Admin { | |
id: string; | |
role: string; | |
} | |
interface User { | |
email: string; | |
} | |
function redirect(usr: Admin | User) { |
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
import axios from 'axios' | |
import AsyncStorage from '@react-native-community/async-storage' | |
import React, { useEffect, useState } from 'react' | |
import { Linking } from 'react-native' | |
import InAppBrowser from 'react-native-inappbrowser-reborn' | |
import { LoadingIndicator } from '../LoadingIndicator' | |
interface AuthPortalProps { | |
client_id: string | |
scopes: string[] |
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
generate: | |
@echo "Adding TypeScript as dependency..." | |
@yarn add typescript -D | |
@echo "Creating tsconfig..." | |
@npx tsconfig.json | |
@echo "Adding eslint and prettier dependencies..." | |
@yarn add eslint prettier eslint-config-airbnb-typescript-prettier -D | |
@echo "Creating eslint config..." | |
@touch .eslintrc.js | |
@echo "module.exports = {\n extends: ['airbnb-typescript-prettier'],\n rules: {\n // just say 'no' to default exports!\n 'import/prefer-default-export': 'off',\n 'import/no-default-export': 'error',\n }\n };" >> .eslintrc.js |