Skip to content

Commit 8bfa326

Browse files
committed
add 2 ts medium challenges and update nvim dot files
1 parent d9b8fec commit 8bfa326

File tree

7 files changed

+182
-8
lines changed

7 files changed

+182
-8
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
645 - Diff
3+
-------
4+
by ZYSzys (@ZYSzys) #medium #object
5+
6+
### Question
7+
8+
Get an `Object` that is the difference between `O` & `O1`
9+
10+
> View on GitHub: https://tsch.js.org/645
11+
*/
12+
13+
/* _____________ Your Code Here _____________ */
14+
15+
type Diff<O, O1> = Omit<O & O1, keyof O & keyof O1>
16+
17+
type D = Diff<Foo, Bar>;
18+
type D1 = Diff<Bar, Foo>;
19+
type D2 = Diff<Coo, Foo>;
20+
21+
const d2: D2 = {
22+
age: "",
23+
gender: 1,
24+
}
25+
26+
/* _____________ Test Cases _____________ */
27+
import type { Equal, Expect } from "@type-challenges/utils";
28+
29+
type Foo = {
30+
name: string;
31+
age: string;
32+
};
33+
type Bar = {
34+
name: string;
35+
age: string;
36+
gender: number;
37+
};
38+
type Coo = {
39+
name: string;
40+
gender: number;
41+
};
42+
43+
type cases = [
44+
Expect<Equal<Diff<Foo, Bar>, { gender: number }>>,
45+
Expect<Equal<Diff<Bar, Foo>, { gender: number }>>,
46+
Expect<Equal<Diff<Foo, Coo>, { age: string; gender: number }>>,
47+
Expect<Equal<Diff<Coo, Foo>, { age: string; gender: number }>>
48+
];
49+
50+
/* _____________ Further Steps _____________ */
51+
/*
52+
> Share your solutions: https://tsch.js.org/645/answer
53+
> View solutions: https://tsch.js.org/645/solutions
54+
> More Challenges: https://tsch.js.org
55+
*/
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
949 - AnyOf
3+
-------
4+
by null (@kynefuk) #medium #array
5+
6+
### Question
7+
8+
Implement Python liked `any` function in the type system. A type takes the Array and returns `true` if any element of the Array is true. If the Array is empty, return `false`.
9+
10+
For example:
11+
12+
```ts
13+
type Sample1 = AnyOf<[1, '', false, [], {}]> // expected to be true.
14+
type Sample2 = AnyOf<[0, '', false, [], {}]> // expected to be false.
15+
```
16+
17+
> View on GitHub: https://tsch.js.org/949
18+
*/
19+
20+
/* _____________ Your Code Here _____________ */
21+
22+
// my try
23+
type AnyOf<T extends readonly any[]> = T extends [infer El, ...infer R]
24+
? El extends 0 | "" | false | [] | undefined | null | { [key: string]: never }
25+
? AnyOf<R>
26+
: true
27+
: false;
28+
29+
// after some thinking
30+
type AnyOf2<T extends readonly any[]> = T[number] extends 0 | "" | false | [] | undefined | null | { [key: string]: never }
31+
? false
32+
: true;
33+
34+
type Sample1 = AnyOf<[1, "", false, [], {}]>; // expected to be true.
35+
// ^?
36+
type Sample2 = AnyOf<[0, "", false, [], null, undefined]>; // expected to be false.
37+
// ^?
38+
39+
/* _____________ Test Cases _____________ */
40+
import type { Equal, Expect } from "@type-challenges/utils";
41+
42+
type cases = [
43+
Expect<
44+
Equal<AnyOf<[1, "test", true, [1], { name: "test" }, { 1: "test" }]>, true>
45+
>,
46+
Expect<Equal<AnyOf<[1, "", false, [], {}]>, true>>,
47+
Expect<Equal<AnyOf<[0, "test", false, [], {}]>, true>>,
48+
Expect<Equal<AnyOf<[0, "", true, [], {}]>, true>>,
49+
Expect<Equal<AnyOf<[0, "", false, [1], {}]>, true>>,
50+
Expect<Equal<AnyOf<[0, "", false, [], { name: "test" }]>, true>>,
51+
Expect<Equal<AnyOf<[0, "", false, [], { 1: "test" }]>, true>>,
52+
Expect<
53+
Equal<AnyOf<[0, "", false, [], { name: "test" }, { 1: "test" }]>, true>
54+
>,
55+
Expect<Equal<AnyOf<[0, "", false, [], {}, undefined, null]>, false>>,
56+
Expect<Equal<AnyOf<[]>, false>>
57+
];
58+
59+
/* _____________ Further Steps _____________ */
60+
/*
61+
> Share your solutions: https://tsch.js.org/949/answer
62+
> View solutions: https://tsch.js.org/949/solutions
63+
> More Challenges: https://tsch.js.org
64+
*/
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
lua require('plugins')
2-
lua require('coc')
3-
lua require('remaps')
4-
51
"""""""""""""" vim config
62
set noswapfile nobackup
73
set undofile undodir=~/.config/nvim/undodir
84
set autoindent expandtab tabstop=2 shiftwidth=2
5+
set mouse=
6+
7+
let g:NERDTreeWinSize = 40
98

109

1110
"""""""""" Remember position of last edit and return on reopen
1211
if has("autocmd")
1312
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
1413
endif
1514

15+
"""""""""""" Search expression in files of given path
16+
command! -bang -nargs=* Rg2
17+
\ call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case ".<q-args>, 1, {'dir': system('git -C '.expand('%:p:h').' rev-parse --show-toplevel 2> /dev/null')[:-2]}, <bang>0)

OS/Linux/Dotfiles/nvim/init.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require('plugins')
2+
require('coc')
3+
require('remaps')
4+
require('mason').setup()
5+
require('lsp')
6+
7+
vim.cmd('source ~/.config/nvim/config.vim')
8+
9+

OS/Linux/Dotfiles/nvim/lua/lsp.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require("lspconfig")["tsserver"].setup({
2+
on_attach = function(client, bufnr)
3+
require("twoslash-queries").attach(client, bufnr)
4+
end,
5+
})

OS/Linux/Dotfiles/nvim/lua/plugins.lua

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,51 @@ vim.api.nvim_set_keymap("n", "<Leader><Leader>",
88
[[<cmd>lua require('telescope').extensions.recent_files.pick()<CR>]],
99
{noremap = true, silent = true})
1010

11+
function search_word_all()
12+
local input_string = vim.fn.input("Search For > ")
13+
if (input_string == '') then
14+
return
15+
end
16+
builtin.grep_string({
17+
search = input_string,
18+
})
19+
end
20+
vim.keymap.set('n', '<leader>fa', search_word_all, {})
21+
22+
1123
return require('packer').startup(function(use)
24+
-- packers
1225
use 'wbthomason/packer.nvim'
26+
use {
27+
"williamboman/mason.nvim",
28+
run = ":MasonUpdate" -- :MasonUpdate updates registry contents
29+
}
1330
use {'neoclide/coc.nvim', branch = 'release'}
31+
32+
-- navigation
1433
use {
1534
'nvim-telescope/telescope.nvim', tag = '0.1.1',
1635
requires = { {'nvim-lua/plenary.nvim'} }
1736
}
37+
use { 'junegunn/fzf', run = ":call fzf#install()" }
38+
use { 'junegunn/fzf.vim' }
1839
use "smartpde/telescope-recent-files"
19-
use "jiangmiao/auto-pairs"
40+
use "preservim/nerdtree"
41+
42+
43+
-- ts
44+
use "leafgarland/typescript-vim"
2045
use "tpope/vim-surround"
2146
use "tpope/vim-fugitive"
22-
use "preservim/nerdtree"
2347
use {
2448
"prettier/vim-prettier",
2549
run='npx yarn install --frozen-lockfile --production'
2650
}
51+
use "neovim/nvim-lspconfig"
52+
use "marilari88/twoslash-queries.nvim"
53+
use "jiangmiao/auto-pairs"
54+
55+
-- other languages
2756
use "wuelnerdotexe/vim-astro"
57+
2858
end)

OS/Linux/Dotfiles/nvim/lua/remaps.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,20 @@ function map(mode, lhs, rhs, opts)
77
vim.api.nvim_set_keymap(mode, lhs, rhs, options)
88
end
99

10-
map("n", "nn", ":NERDTreeToggle<cr>")
10+
11+
map("n", ",,", ":NERDTreeToggle<cr>")
12+
map("n", "mm", ":Files<cr>")
1113
map("n", "zz", "<ESC>:update<cr>")
1214
map("n", "<C-s>","<C-^>")
1315
map("n", "ff", ":Prettier<cr> | :update | !cargo fmt<cr>")
16+
map("n", "<leader>fc", ":Rg<cr>")
17+
map("n", "<C-j>", "<C-W>j")
18+
map("n", "<C-k>", "<C-W>k")
19+
map("n", "<C-h>", "<C-W>h")
20+
map("n", "<C-l>", "<C-W>l")
1421

15-
map("i", "nn", "<ESC>:NERDTreeToggle<cr>")
1622
map("i", "zz", "<ESC>:update<cr>")
1723
map("i", "jj", "<ESC>")
24+
25+
26+

0 commit comments

Comments
 (0)