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 search(tree, word) { | |
| let root = null | |
| do{ | |
| root = Object.keys(tree).find( k => word.indexOf(k) == 0) | |
| word = word.replace(root, "") | |
| tree = tree[root] | |
| } while(root) |
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 findPrefixes(words) { | |
| let sample = words[0] | |
| let currentSet = [] | |
| let lastCommonSet = [] | |
| let currentPrefix = ""; | |
| let lastValidPrefix = ""; | |
| for(let i = sample.length; i > 0; i--) { | |
| currentPrefix = sample.slice(0, i) | |
| currentSet = words.filter( w => w.indexOf(currentPrefix) == 0) | |
| if(currentSet.length > 0 && currentSet.length > lastCommonSet.length) { |
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
| while(suffixes.length > 0) { | |
| createTree(tree) | |
| } |
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 createTree(tree) { | |
| let ret = findPrefixes(suffixes) | |
| suffixes = removeWordsFromList(ret.usedWords, suffixes) | |
| root = ret.group.shift() | |
| tree[root] = {pending: ret.group} | |
| while(tree[root].pending.length > 0) { | |
| ret = findPrefixes(tree[root].pending) | |
| if(ret.group.length == 1) { //it's a leaf | |
| tree[root][ret.group[0]] = "*" |
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 getAllSortedSuffixes(w) { | |
| let suffixes = [] | |
| for(let i = 0; i < w.length; i++) { | |
| suffixes.push(w.slice(i)) | |
| } | |
| return suffixes.sort() | |
| } | |
| let tree = {} |
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
| useEffect(() => { | |
| listen('new-todo', () => { | |
| inputRef.current.focus() | |
| }) | |
| }, []) |
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
| tauri::Builder::default() | |
| .menu(menu) | |
| .run(tauri::generate_context!()) | |
| .expect("error while running tauri application"); |
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, { useEffect, useState, useRef } from 'react'; | |
| import Sentiment from 'sentiment'; | |
| import 'bootstrap/dist/css/bootstrap.min.css'; | |
| const sentiment = new Sentiment(); | |
| function TodoApp() { | |
| const [todos, setTodos] = useState([]); | |
| const [input, setInput] = useState(''); | |
| const inputRef = useRef() |
NewerOlder