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
| const isBalanced = str => { | |
| const arr = str.split(''); | |
| const res = arr.reduce((acc, item) => { | |
| if ( acc.slice(-1)[0] === '(' ) { | |
| if ( item === ')' ) { | |
| acc.pop(); | |
| return acc; | |
| } | |
| } | |
| if ( item === '(' || item === ')' ) { |
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
| // returns an array containing all permutations of a given string | |
| const permute = str => { | |
| let permutations = []; | |
| if ( str.length <= 1 ) { | |
| return [str]; | |
| } | |
| for ( let i = 0; i < str.length; i++ ) { | |
| let char = str[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
| const fs = require('fs'); | |
| fs.readdir('.', 'utf8', (err, files) => { | |
| if ( err ) { | |
| console.log('Error: ', err); | |
| return; | |
| } | |
| let largestLength = files.slice().sort((a,b) => b.length - a.length)[0].length; | |
| let columns = Math.floor( process.stdout.columns / largestLength ); |
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
| const { RESTDataSource } = require('apollo-datasource-rest'); | |
| class GoogleBooksAPI extends RESTDataSource { | |
| constructor() { | |
| super(); | |
| this.baseURL = 'https://www.googleapis.com/books/v1/'; | |
| } | |
| async getBooks() { | |
| const res = await this.get(`volumes?q=harry+potter`); |
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
| import { GraphQLClient } from 'graphql-request'; | |
| const client = new GraphQLClient('http://localhost:4000/api'); | |
| const handleSearch = (value) => { | |
| client.request(/* GraphQL */` | |
| query getBookList($search: String!) { | |
| search(searchString: $search) { | |
| count | |
| books { |
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
| import React, { useState } from 'react'; | |
| import { TextInputFormElement } from './TextInputFormElement'; | |
| import { NumberInputFormElement } from './NumberInputFormElement'; | |
| const data = ['a', 1, 'b', 2, 'c', 3, 'd', 4, 'e', 5]; | |
| const App = () => { | |
| const [activeElement, setActiveElement] = useState('a'); | |
| return ( | |
| <div id='intersector' className='intersection-line'> |
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
| import { useEffect } from 'react'; | |
| export const useActiveOnIntersect = (setActiveElement, elementRef) => { | |
| const options = { | |
| root: document.querySelector('#intersector'), | |
| rootMargin: '0px', | |
| threshold: 1.0, | |
| }; | |
| const callback = (entries) => { |
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
| import { useEffect } from 'react'; | |
| export const useFocusOnActive = (active, inputRef) => { | |
| useEffect(() => { | |
| if ( active && inputRef.current ) { | |
| inputRef.current.focus(); | |
| return () => inputRef.current.blur(); | |
| } | |
| }, [active]); | |
| }; |
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
| import React, { useRef } from 'react'; | |
| import { useActiveOnIntersect } from './hooks/useActiveOnIntersect'; | |
| import { useFocusOnActive } from './hooks/useFocusOnActive'; | |
| export const TextInputFormElement = ({ char, active, setActiveElement }) => { | |
| const containerEl = useRef(); | |
| const inputRef = useRef(); | |
| useActiveOnIntersect(() => setActiveElement(char), containerEl); | |
| useFocusOnActive(active, inputRef); |
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
| { | |
| "Punctuations": [ | |
| "!", ".", ":", "'", ";", ",", "?", | |
| "@", "#", "$", "%", "^", "&", "*", | |
| "(", ")", "[", "]", "\"", "\\", "/", | |
| "-", "_", "+", "=", "<", ">", "|" | |
| ], | |
| "StopWords": [ | |
| "a", "able", "about", "across", "after", "all", "almost", "also", "am", "among", "an", | |
| "and", "any", "are", "as", "at", "be", "because", "been", "but", "by", "can", "cannot", |
OlderNewer