Map [1]
Operation | Time Complexity |
---|---|
Access | O(log n) |
Search | O(log n) |
Insertion | O(n) for <= 32 elements, O(log n) for > 32 elements [2] |
Deletion | O(n) for <= 32 elements, O(log n) for > 32 elements |
#!/bin/sh | |
# Userland mode (~$USER/), (~/). | |
# ~/.fonts is now deprecated and that | |
#FONT_HOME=~/.fonts | |
# ~/.local/share/fonts should be used instead | |
FONT_HOME=~/.local/share/fonts | |
echo "installing fonts at $PWD to $FONT_HOME" | |
mkdir -p "$FONT_HOME/adobe-fonts/source-code-pro" |
function primeString(s, count = 1) { | |
// 如果字串中有重複的模式,最少也會重複 1 次,故迭代超過字串長度的一半還沒找到就不用找了 | |
if(count > s.length / 2) { return true } | |
// 每次迭代將字串的一小塊,設定為分割陣列的符號 chunk | |
let chunk = s.slice(0, count) | |
// 被 chunk 切過的部分會變成陣列中的空元素,此行判斷是不是能夠將陣列切成重複的小塊 | |
// 如果切完後全部的陣列元素都是空的,代表字串被 chunk 整除,恭喜找到規律。 | |
let grouped = s.split(chunk).every(i => i === '') | |
#!/bin/sh | |
# Userland mode (~$USER/), (~/). | |
# ~/.fonts is now deprecated and that | |
#FONT_HOME=~/.fonts | |
# ~/.local/share/fonts should be used instead | |
FONT_HOME=~/.local/share/fonts | |
echo "installing fonts at $PWD to $FONT_HOME" | |
mkdir -p "$FONT_HOME/adobe-fonts/source-code-pro" |
Community
Cheatsheets
Books
$: (Dollar Colon) is basically a shorthand version of $LOAD_PATH. $: contains an array of paths that your script will search through when using require. | |
$0 (Dollar Zero) contains the name of the ruby program being run. This is typically the script name. | |
$* (Dollar Splat) is basically shorthand for ARGV. $* contains the command line arguments that were passed to the script. | |
$? (Dollar Question Mark) returns the exit status of the last child process to finish. | |
$$ (Dollar Dollar) returns the process number of the program currently being ran. | |
$~ (Dollar Tilde) contains the MatchData from the previous successful pattern match. | |
$1, $2, $3, $4 etc represent the content of the previous successful pattern match. | |
$& (Dollar Ampersand) contains the matched string from the previous successful pattern match. | |
$+ (Dollar Plus) contains the last match from the previous successful pattern match. | |
$` (Dollar Backtick) contains the string before the actual matched string of the previous successful pattern match. |