Skip to content

Commit

Permalink
Replace js with javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
krahets committed Feb 7, 2023
1 parent 0407cc7 commit 22b7d65
Show file tree
Hide file tree
Showing 27 changed files with 127 additions and 92 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ hello-algo.iml
.cache/
scripts/
docs/overrides/

# build
build/
site/
12 changes: 6 additions & 6 deletions docs/chapter_array_and_linkedlist/linked_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ comments: true

=== "JavaScript"

```js title=""
```javascript title=""
/* 链表结点结构体 */
class ListNode {
val;
Expand Down Expand Up @@ -225,7 +225,7 @@ comments: true

=== "JavaScript"

```js title="linked_list.js"
```javascript title="linked_list.js"
/* 初始化链表 1 -> 3 -> 2 -> 5 -> 4 */
// 初始化各个结点
const n0 = new ListNode(1);
Expand Down Expand Up @@ -385,7 +385,7 @@ comments: true

=== "JavaScript"

```js title="linked_list.js"
```javascript title="linked_list.js"
/* 在链表的结点 n0 之后插入结点 P */
function insert(n0, P) {
let n1 = n0.next;
Expand Down Expand Up @@ -537,7 +537,7 @@ comments: true

=== "JavaScript"

```js title="linked_list.js"
```javascript title="linked_list.js"
/* 访问链表中索引为 index 的结点 */
function access(head, index) {
for (let i = 0; i < index; i++) {
Expand Down Expand Up @@ -660,7 +660,7 @@ comments: true

=== "JavaScript"

```js title="linked_list.js"
```javascript title="linked_list.js"
/* 在链表中查找值为 target 的首个结点 */
function find(head, target) {
let index = 0;
Expand Down Expand Up @@ -815,7 +815,7 @@ comments: true

=== "JavaScript"

```js title=""
```javascript title=""
/* 双向链表结点类 */
class ListNode {
val;
Expand Down
14 changes: 7 additions & 7 deletions docs/chapter_array_and_linkedlist/list.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ comments: true

=== "JavaScript"

```js title="list.js"
```javascript title="list.js"
/* 初始化列表 */
// 无初始值
const list1 = [];
Expand Down Expand Up @@ -154,7 +154,7 @@ comments: true

=== "JavaScript"

```js title="list.js"
```javascript title="list.js"
/* 访问元素 */
const num = list[1]; // 访问索引 1 处的元素

Expand Down Expand Up @@ -292,7 +292,7 @@ comments: true

=== "JavaScript"

```js title="list.js"
```javascript title="list.js"
/* 清空列表 */
list.length = 0;

Expand Down Expand Up @@ -462,7 +462,7 @@ comments: true

=== "JavaScript"

```js title="list.js"
```javascript title="list.js"
/* 通过索引遍历列表 */
let count = 0;
for (let i = 0; i < list.length; i++) {
Expand Down Expand Up @@ -586,7 +586,7 @@ comments: true

=== "JavaScript"

```js title="list.js"
```javascript title="list.js"
/* 拼接两个列表 */
const list1 = [6, 8, 7, 10, 9];
list.push(...list1); // 将列表 list1 拼接到 list 之后
Expand Down Expand Up @@ -664,7 +664,7 @@ comments: true

=== "JavaScript"

```js title="list.js"
```javascript title="list.js"
/* 排序列表 */
list.sort((a, b) => a - b); // 排序后,列表元素从小到大排列
```
Expand Down Expand Up @@ -835,7 +835,7 @@ comments: true

=== "JavaScript"

```js title="my_list.js"
```javascript title="my_list.js"
/* 列表类简易实现 */
class MyList {
#nums = new Array(); // 数组(存储列表元素)
Expand Down
18 changes: 9 additions & 9 deletions docs/chapter_computational_complexity/space_complexity.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ comments: true

=== "JavaScript"

```js title=""
```javascript title=""
/* 类 */
class Node {
val;
Expand Down Expand Up @@ -309,7 +309,7 @@ comments: true

=== "JavaScript"

```js title=""
```javascript title=""
function algorithm(n) {
const a = 0; // O(1)
const b = new Array(10000); // O(1)
Expand Down Expand Up @@ -455,7 +455,7 @@ comments: true

=== "JavaScript"

```js title=""
```javascript title=""
function constFunc() {
// do something
return 0;
Expand Down Expand Up @@ -622,7 +622,7 @@ $$

=== "JavaScript"

```js title="space_complexity.js"
```javascript title="space_complexity.js"
/* 常数阶 */
function constant(n) {
// 常量、变量、对象占用 O(1) 空间
Expand Down Expand Up @@ -785,7 +785,7 @@ $$

=== "JavaScript"

```js title="space_complexity.js"
```javascript title="space_complexity.js"
/* 线性阶 */
function linear(n) {
// 长度为 n 的数组占用 O(n) 空间
Expand Down Expand Up @@ -928,7 +928,7 @@ $$

=== "JavaScript"

```js title="space_complexity.js"
```javascript title="space_complexity.js"
/* 线性阶(递归实现) */
function linearRecur(n) {
console.log(`递归 n = ${n}`);
Expand Down Expand Up @@ -1031,7 +1031,7 @@ $$

=== "JavaScript"

```js title="space_complexity.js"
```javascript title="space_complexity.js"
/* 平方阶 */
function quadratic(n) {
// 矩阵占用 O(n^2) 空间
Expand Down Expand Up @@ -1162,7 +1162,7 @@ $$

=== "JavaScript"

```js title="space_complexity.js"
```javascript title="space_complexity.js"
/* 平方阶(递归实现) */
function quadraticRecur(n) {
if (n <= 0) return 0;
Expand Down Expand Up @@ -1272,7 +1272,7 @@ $$

=== "JavaScript"

```js title="space_complexity.js"
```javascript title="space_complexity.js"
/* 指数阶(建立满二叉树) */
function buildTree(n) {
if (n === 0) return null;
Expand Down
4 changes: 2 additions & 2 deletions docs/chapter_computational_complexity/space_time_tradeoff.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ comments: true

=== "JavaScript"

```js title="leetcode_two_sum.js"
```javascript title="leetcode_two_sum.js"
function twoSumBruteForce(nums, target) {
const n = nums.length;
// 两层循环,时间复杂度 O(n^2)
Expand Down Expand Up @@ -208,7 +208,7 @@ comments: true

=== "JavaScript"

```js title="leetcode_two_sum.js"
```javascript title="leetcode_two_sum.js"
function twoSumHashTable(nums, target) {
// 辅助哈希表,空间复杂度 O(n)
let m = {};
Expand Down
32 changes: 16 additions & 16 deletions docs/chapter_computational_complexity/time_complexity.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ $$

=== "JavaScript"

```js title=""
```javascript title=""
// 在某运行平台下
function algorithm(n) {
var a = 2; // 1 ns
Expand Down Expand Up @@ -252,7 +252,7 @@ $$

=== "JavaScript"

```js title=""
```javascript title=""
// 算法 A 时间复杂度:常数阶
function algorithm_A(n) {
console.log(0);
Expand Down Expand Up @@ -445,7 +445,7 @@ $$

=== "JavaScript"

```js title=""
```javascript title=""
function algorithm(n){
var a = 1; // +1
a += 1; // +1
Expand Down Expand Up @@ -646,7 +646,7 @@ $$

=== "JavaScript"

```js title=""
```javascript title=""
function algorithm(n) {
let a = 1; // +0(技巧 1)
a = a + n; // +0(技巧 1)
Expand Down Expand Up @@ -826,7 +826,7 @@ $$

=== "JavaScript"

```js title="time_complexity.js"
```javascript title="time_complexity.js"
/* 常数阶 */
function constant(n) {
let count = 0;
Expand Down Expand Up @@ -944,7 +944,7 @@ $$

=== "JavaScript"

```js title="time_complexity.js"
```javascript title="time_complexity.js"
/* 线性阶 */
function linear(n) {
let count = 0;
Expand Down Expand Up @@ -1057,7 +1057,7 @@ $$

=== "JavaScript"

```js title="time_complexity.js"
```javascript title="time_complexity.js"
/* 线性阶(遍历数组) */
function arrayTraversal(nums) {
let count = 0;
Expand Down Expand Up @@ -1181,7 +1181,7 @@ $$

=== "JavaScript"

```js title="time_complexity.js"
```javascript title="time_complexity.js"
/* 平方阶 */
function quadratic(n) {
let count = 0;
Expand Down Expand Up @@ -1333,7 +1333,7 @@ $$

=== "JavaScript"

```js title="time_complexity.js"
```javascript title="time_complexity.js"
/* 平方阶(冒泡排序) */
function bubbleSort(nums) {
let count = 0; // 计数器
Expand Down Expand Up @@ -1524,7 +1524,7 @@ $$

=== "JavaScript"

```js title="time_complexity.js"
```javascript title="time_complexity.js"
/* 指数阶(循环实现) */
function exponential(n) {
let count = 0,
Expand Down Expand Up @@ -1679,7 +1679,7 @@ $$

=== "JavaScript"

```js title="time_complexity.js"
```javascript title="time_complexity.js"
/* 指数阶(递归实现) */
function expRecur(n) {
if (n == 1) return 1;
Expand Down Expand Up @@ -1783,7 +1783,7 @@ $$

=== "JavaScript"

```js title="time_complexity.js"
```javascript title="time_complexity.js"
/* 对数阶(循环实现) */
function logarithmic(n) {
let count = 0;
Expand Down Expand Up @@ -1909,7 +1909,7 @@ $$

=== "JavaScript"

```js title="time_complexity.js"
```javascript title="time_complexity.js"
/* 对数阶(递归实现) */
function logRecur(n) {
if (n <= 1) return 0;
Expand Down Expand Up @@ -2014,7 +2014,7 @@ $$

=== "JavaScript"

```js title="time_complexity.js"
```javascript title="time_complexity.js"
/* 线性对数阶 */
function linearLogRecur(n) {
if (n <= 1) return 1;
Expand Down Expand Up @@ -2156,7 +2156,7 @@ $$

=== "JavaScript"

```js title="time_complexity.js"
```javascript title="time_complexity.js"
/* 阶乘阶(递归实现) */
function factorialRecur(n) {
if (n == 0) return 1;
Expand Down Expand Up @@ -2338,7 +2338,7 @@ $$

=== "JavaScript"

```js title="worst_best_time_complexity.js"
```javascript title="worst_best_time_complexity.js"
/* 生成一个数组,元素为 { 1, 2, ..., n },顺序被打乱 */
function randomNumbers(n) {
const nums = Array(n);
Expand Down
2 changes: 1 addition & 1 deletion docs/chapter_data_structure/data_and_memory.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ comments: true

=== "JavaScript"

```js title=""
```javascript title=""
/* JavaScript 的数组可以自由存储各种基本数据类型和对象 */
const array = [0, 0.0, 'a', false];
```
Expand Down
4 changes: 2 additions & 2 deletions docs/chapter_graph/graph_operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ comments: true

=== "JavaScript"

```js title="graph_adjacency_matrix.js"
```javascript title="graph_adjacency_matrix.js"

```

Expand Down Expand Up @@ -390,7 +390,7 @@ comments: true

=== "JavaScript"

```js title="graph_adjacency_list.js"
```javascript title="graph_adjacency_list.js"

```

Expand Down
Loading

0 comments on commit 22b7d65

Please sign in to comment.