<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>JavaScript on Yosgi</title><link>https://yosgi.github.io/en/tags/javascript/</link><description>Recent content in JavaScript on Yosgi</description><generator>Hugo</generator><language>en</language><lastBuildDate>Mon, 29 Jun 2026 09:20:51 +0000</lastBuildDate><atom:link href="https://yosgi.github.io/en/tags/javascript/index.xml" rel="self" type="application/rss+xml"/><item><title>AI Won’t Replace Software Engineers. It Will Replace the Parts of Coding We Never Loved.</title><link>https://yosgi.github.io/en/post/ai-won-t-replace-software-engineers-it-will-replace-the-parts-of-coding-we-never-loved/</link><pubDate>Thu, 21 May 2026 23:28:56 +1200</pubDate><guid>https://yosgi.github.io/en/post/ai-won-t-replace-software-engineers-it-will-replace-the-parts-of-coding-we-never-loved/</guid><description>AI will not replace software engineers as a whole. It will remove much of the repetitive, mechanical work and give engineers more leverage to focus on judgment, systems, users, and building better products.</description></item><item><title>138-Copying a linked list with random pointers</title><link>https://yosgi.github.io/en/post/138-copying-a-linked-list-with-random-pointers/</link><pubDate>Thu, 22 Jul 2021 00:00:00 +1200</pubDate><guid>https://yosgi.github.io/en/post/138-copying-a-linked-list-with-random-pointers/</guid><description>The idea behind the question is to use double pointers to point to the old and new nodes, and then add a map to map the old and new nodes. recursion var listMap = new Map() var copyRandomList = function(head) { if(head === null) return head if (listMap.get(head)) { return listMap.get(head) } let newNode = new Node(head.val,null,null) listMap.set(head, newNode) newNode.next = copyRandomList(head.next) newNode.random = copyRandomList(head.random) return newNode }; ```Iteration ```javascript var copyRandomList = function(head) { if(head == null) return head var listMap = new Map() listMap.set(null,null) var cur = head while (cur!= null) { listMap.set(cur,new Node(cur.val,null,null)) cur = cur.next } cur = head while (cur!= null) { listMap.get(cur).next = listMap.get(cur.next) listMap.get(cur).random = listMap.get(cur.random) cur = cur.next } return listMap.get(head) };The idea behind the question is to use double pointers to point to the old and new nodes, and then add a map to map the old and new nodes.</description></item><item><title>865 - Minimum subtree with all deepest nodes</title><link>https://yosgi.github.io/en/post/865-minimum-subtree-with-all-deepest-nodes/</link><pubDate>Sun, 21 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/865-minimum-subtree-with-all-deepest-nodes/</guid><description>Time: 60 minutes I was misled by the depth of the question and thought that the calculation depth should be done from top to bottom. In fact, it can be done from bottom to top. If the left and right subtrees have the same height, return the node itself and its depth. If the left subtree is deeper, it means that the smallest and deepest part is in the left subtree. Return the left subtree and its own depth.</description></item><item><title>783-Binary Search Tree Node Minimum Distance</title><link>https://yosgi.github.io/en/post/783-binary-search-tree-node-minimum-distance/</link><pubDate>Thu, 18 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/783-binary-search-tree-node-minimum-distance/</guid><description>Time: 10 minutes Solve by using the property of pre-order traversal of binary tree var minDiffInBST = function(root) { var min = Infinity var pre = null var dfs = function (root) { if (!root) return if (root.left) { dfs(root.left) } if (pre == null) { pre = root.val } else { console.log(pre,root.val) var reduce = Math.abs(pre - root.val) min = Math.min(min,reduce) pre = root.val } if (root.right) { dfs(root.right) } } dfs(root) return min };</description></item><item><title>1448-Count the number of good nodes in a binary tree</title><link>https://yosgi.github.io/en/post/1448-count-the-number-of-good-nodes-in-a-binary-tree/</link><pubDate>Wed, 17 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/1448-count-the-number-of-good-nodes-in-a-binary-tree/</guid><description>Notes on counting good nodes in a binary tree using DFS with a running max.</description></item><item><title>1325-Delete the leaf node of the given value</title><link>https://yosgi.github.io/en/post/1325-delete-the-leaf-node-of-the-given-value/</link><pubDate>Wed, 17 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/1325-delete-the-leaf-node-of-the-given-value/</guid><description>Post-order traversal approach to delete target-valued leaf nodes using a dummy root.</description></item><item><title>129-Find the sum of numbers from the root node to the leaf node</title><link>https://yosgi.github.io/en/post/129-find-the-sum-of-numbers-from-the-root-node-to-the-leaf-node/</link><pubDate>Tue, 16 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/129-find-the-sum-of-numbers-from-the-root-node-to-the-leaf-node/</guid><description>The question is about starting from the root node. The first thing that comes to mind is top-down DFS, passing parameters downward, and the end condition has no left or right children. Start with the pre-order traversal, and you can assume that all the previous nodes have been processed. var sumNumbers = function(root) { var ans = 0 var DFS = function (root,path) { if (!root) return path += root.val if (!root.left &amp;&amp; !root.right) { ans += Number(path) } root.left &amp;&amp; DFS(root.left,path) DFS(root.right, path) } DFS(root,'') return ans };The question is about starting from the root node. The first thing that comes to mind is top-down DFS, passing parameters downward, and the end condition has no left or right children.</description></item><item><title>863-All nodes with distance -K- in a binary tree</title><link>https://yosgi.github.io/en/post/863-all-nodes-with-distance-k-in-a-binary-tree/</link><pubDate>Sat, 13 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/863-all-nodes-with-distance-k-in-a-binary-tree/</guid><description>Time: 60 minutes The idea is still very simple. First use DFS to add a parent to each node, and find the required target by the way. Then starting from the target, use DFS to find a point K away from the target. Find all the parents of target in turn and use DFS to find the point with a distance K. The reason why it takes so much time is that after finding the parent, DFS is used to find it back, causing a memory overflow.</description></item><item><title>222-Number of nodes in a complete binary tree</title><link>https://yosgi.github.io/en/post/222-number-of-nodes-in-a-complete-binary-tree/</link><pubDate>Sat, 13 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/222-number-of-nodes-in-a-complete-binary-tree/</guid><description>Time: 80 minutes The first reaction when I got the question was of course to solve it with DFS. But this is a complete binary tree, so we should use the properties of a complete binary tree. You can examine the depth of the left and right subtrees of the binary tree If the left depth is greater than the right depth, it means that the right side is full. The number of full nodes is 2 to the power of n - 1, plus the root is 2 to the power of n, and continue recursively on the left side.</description></item><item><title>450-Delete a node in a binary search tree</title><link>https://yosgi.github.io/en/post/450-delete-a-node-in-a-binary-search-tree/</link><pubDate>Thu, 11 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/450-delete-a-node-in-a-binary-search-tree/</guid><description>Time: 30 minutes The question is divided into two parts to be solved, search and delete The search part is to find the node. You can find the required node according to the properties of the binary search tree. There are three types of deletion If there is only a left child, replace it with the left child. If there is only a right child, replace it with the right child. If there is neither child, assign null. (Since there was a recursive assignment earlier, this will succeed.) If there are both children, store the left child, replace it with the right child, and then find the left child’s position on the right. var deleteNode = function(root, key) { function insert(root,node) { if (root.val &gt; node.val) { if (!root.left) { root.left = node } else { insert(root.left,node) } } else { if (!root.right) { root.right = node } else { insert(root.right,node) } } } function search(root) { if (!root) { return null } if (root.val &gt; key) { root.left = search(root.left) } else if (root.val &lt; key){ root.right = search(root.right) } else { if (!root.left &amp;&amp; !root.right) { root = null } else if (root.left &amp;&amp; root.right) { var left = root.left root = root.right insert(root,left) } else if (root.left) { root = root.left } else if (root.right) { root = root.right } } return root } return search(root) };Points to note</description></item><item><title>116-Fill in the next right node pointer of each node</title><link>https://yosgi.github.io/en/post/116-fill-in-the-next-right-node-pointer-of-each-node/</link><pubDate>Wed, 10 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/116-fill-in-the-next-right-node-pointer-of-each-node/</guid><description>Time: 25 minutes The main idea is to use the stack. The difference from the ordinary level-order traversal is that the stack is cleared every time var connect = function(root) { if (!root) return null var stack = [root] while(stack.length) { var _stack = [...stack,null] stack = [] var pre = _stack.shift() while(_stack.length || pre) { pre.left &amp;&amp; stack.push(pre.left) pre.right &amp;&amp; stack.push(pre.right) pre.next = _stack.shift() pre = pre.next } } return root};Obviously, the memory space of On I used does not meet the constant space requirement of the question, considering that the links of each layer can be found in the form of a linked list by relying on the parent node.</description></item><item><title>Summary of Binary Trees</title><link>https://yosgi.github.io/en/post/summary-of-binary-trees/</link><pubDate>Sun, 28 Feb 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/summary-of-binary-trees/</guid><description>When traversing a binary tree in front, middle, or post-order, we use a stack to simplify operations. This is because they are all recursive structures of DFS, which means processing from bottom to top. However, I always start writing code from the root node, so I need a stack, and the stack is first-in-first-out. This way, I can process the root node last. Level-order traversal is BFS, from top to bottom. The root element that was enqueued first is also the one I want to process first. This is why DFS uses a stack and BFS uses a queue.</description></item><item><title>Review of login and registration requirements</title><link>https://yosgi.github.io/en/post/review-of-login-and-registration-requirements/</link><pubDate>Sun, 21 Feb 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/review-of-login-and-registration-requirements/</guid><description>A few years ago, the company needed to log in and register, and the estimated construction period was one month. As a result, the project became uncontrollable during the process, and it took almost three months to complete. In order not to waste the overtime work during this period, I reviewed the process of completing the project. About Requirements Review Let’s briefly review the requirements first. Registration/login has three channels: account/password, mobile phone number, and three-party (including WeChat QR code scanning, QQ authorization, and Weibo authorization). Through a series of rules and guidance, you will eventually reach the login/registration success page and then jump to the source web page.</description></item><item><title>DOM event flow</title><link>https://yosgi.github.io/en/post/dom-event-flow/</link><pubDate>Fri, 29 Jan 2021 17:44:40 +1300</pubDate><guid>https://yosgi.github.io/en/post/dom-event-flow/</guid><description>DOM event flow is easy to confuse</description></item><item><title>Hexo upgraded to 5</title><link>https://yosgi.github.io/en/post/hexo-upgraded-to-5/</link><pubDate>Fri, 11 Dec 2020 12:37:55 +1300</pubDate><guid>https://yosgi.github.io/en/post/hexo-upgraded-to-5/</guid><description>Filling Diary</description></item><item><title>Update after a year</title><link>https://yosgi.github.io/en/post/update-after-a-year/</link><pubDate>Fri, 11 Dec 2020 00:17:30 +1300</pubDate><guid>https://yosgi.github.io/en/post/update-after-a-year/</guid><description>One month after leaving Dahua</description></item><item><title>Ajax data transmission optimization</title><link>https://yosgi.github.io/en/post/ajax-data-transmission-optimization/</link><pubDate>Wed, 28 Nov 2018 14:47:40 +1300</pubDate><guid>https://yosgi.github.io/en/post/ajax-data-transmission-optimization/</guid><description>High Performance Javascript Knowledge Points</description></item><item><title>UI interface response optimization</title><link>https://yosgi.github.io/en/post/ui-interface-response-optimization/</link><pubDate>Thu, 22 Nov 2018 16:55:21 +1300</pubDate><guid>https://yosgi.github.io/en/post/ui-interface-response-optimization/</guid><description>High Performance Javascript Knowledge Points</description></item><item><title>Regular expression performance optimization</title><link>https://yosgi.github.io/en/post/regular-expression-performance-optimization/</link><pubDate>Tue, 06 Nov 2018 15:48:14 +1300</pubDate><guid>https://yosgi.github.io/en/post/regular-expression-performance-optimization/</guid><description>High Performance Javascript Knowledge Points</description></item><item><title>Algorithm and process control optimization</title><link>https://yosgi.github.io/en/post/algorithm-and-process-control-optimization/</link><pubDate>Thu, 25 Oct 2018 14:33:59 +1300</pubDate><guid>https://yosgi.github.io/en/post/algorithm-and-process-control-optimization/</guid><description>High Performance Javascript Knowledge Points</description></item><item><title>Performance optimization of DOM operations</title><link>https://yosgi.github.io/en/post/performance-optimization-of-dom-operations/</link><pubDate>Wed, 12 Sep 2018 15:09:33 +1200</pubDate><guid>https://yosgi.github.io/en/post/performance-optimization-of-dom-operations/</guid><description>High Performance Javascript Knowledge Points</description></item><item><title>JavaScript Loading Optimization</title><link>https://yosgi.github.io/en/post/javascript-loading-optimization/</link><pubDate>Tue, 04 Sep 2018 09:23:11 +1200</pubDate><guid>https://yosgi.github.io/en/post/javascript-loading-optimization/</guid><description>Notes from 'High Performance JavaScript'</description></item><item><title>Arrays, stacks, queues</title><link>https://yosgi.github.io/en/post/arrays-stacks-queues/</link><pubDate>Wed, 22 Aug 2018 15:09:45 +1200</pubDate><guid>https://yosgi.github.io/en/post/arrays-stacks-queues/</guid><description>Javascript Data Structures</description></item><item><title>Proxy implementation of data response</title><link>https://yosgi.github.io/en/post/proxy-implementation-of-data-response/</link><pubDate>Fri, 27 Jul 2018 15:56:49 +1200</pubDate><guid>https://yosgi.github.io/en/post/proxy-implementation-of-data-response/</guid><description>Javascript</description></item><item><title>ES5-Inheritance</title><link>https://yosgi.github.io/en/post/es5-inheritance/</link><pubDate>Tue, 17 Jul 2018 09:57:34 +1200</pubDate><guid>https://yosgi.github.io/en/post/es5-inheritance/</guid><description>ES5 knowledge review</description></item><item><title>ES5 - Creating Objects</title><link>https://yosgi.github.io/en/post/es5-creating-objects/</link><pubDate>Fri, 13 Jul 2018 16:51:52 +1200</pubDate><guid>https://yosgi.github.io/en/post/es5-creating-objects/</guid><description>ES5 knowledge review</description></item><item><title>async</title><link>https://yosgi.github.io/en/post/async/</link><pubDate>Wed, 11 Jul 2018 14:47:05 +1200</pubDate><guid>https://yosgi.github.io/en/post/async/</guid><description>"ES6 Standard Introduction" Knowledge Points Summary</description></item><item><title>Generator functions and applications</title><link>https://yosgi.github.io/en/post/generator-functions-and-applications/</link><pubDate>Fri, 06 Jul 2018 18:37:55 +1200</pubDate><guid>https://yosgi.github.io/en/post/generator-functions-and-applications/</guid><description>"ES6 Standard Introduction" Knowledge Points Summary</description></item><item><title>A Brief Introduction to Web Security</title><link>https://yosgi.github.io/en/post/a-brief-introduction-to-web-security/</link><pubDate>Thu, 05 Jul 2018 10:05:36 +1200</pubDate><guid>https://yosgi.github.io/en/post/a-brief-introduction-to-web-security/</guid><description>Web security related content</description></item><item><title>promise</title><link>https://yosgi.github.io/en/post/promise/</link><pubDate>Wed, 27 Jun 2018 13:18:47 +1200</pubDate><guid>https://yosgi.github.io/en/post/promise/</guid><description>"ES6 Standard Introduction" Knowledge Points Summary</description></item><item><title>Javascript deep copy implementation</title><link>https://yosgi.github.io/en/post/javascript-deep-copy-implementation/</link><pubDate>Tue, 26 Jun 2018 17:01:50 +1200</pubDate><guid>https://yosgi.github.io/en/post/javascript-deep-copy-implementation/</guid><description>Javascript Basics</description></item><item><title>Javascript sorting algorithm</title><link>https://yosgi.github.io/en/post/javascript-sorting-algorithm/</link><pubDate>Mon, 25 Jun 2018 18:48:42 +1200</pubDate><guid>https://yosgi.github.io/en/post/javascript-sorting-algorithm/</guid><description>Javascript algorithm sorting algorithm</description></item><item><title>proxy</title><link>https://yosgi.github.io/en/post/proxy/</link><pubDate>Fri, 18 May 2018 09:59:26 +1200</pubDate><guid>https://yosgi.github.io/en/post/proxy/</guid><description>"ES6 Standard Introduction" Knowledge Points Summary</description></item><item><title>Set and Map Data Structures</title><link>https://yosgi.github.io/en/post/set-and-map-data-structures/</link><pubDate>Wed, 02 May 2018 00:00:00 +1200</pubDate><guid>https://yosgi.github.io/en/post/set-and-map-data-structures/</guid><description>"ES6 Standard Introduction" Knowledge Points Summary</description></item><item><title>Object Expansion</title><link>https://yosgi.github.io/en/post/object-expansion/</link><pubDate>Tue, 24 Apr 2018 00:00:00 +1200</pubDate><guid>https://yosgi.github.io/en/post/object-expansion/</guid><description>"ES6 Standard Introduction" Knowledge Points Summary</description></item><item><title>Iterator pattern</title><link>https://yosgi.github.io/en/post/iterator-pattern/</link><pubDate>Fri, 20 Apr 2018 09:41:05 +1200</pubDate><guid>https://yosgi.github.io/en/post/iterator-pattern/</guid><description>Javascript Design Patterns Knowledge Points</description></item><item><title>Proxy Mode</title><link>https://yosgi.github.io/en/post/proxy-mode/</link><pubDate>Thu, 19 Apr 2018 09:46:11 +1200</pubDate><guid>https://yosgi.github.io/en/post/proxy-mode/</guid><description>Javascript Design Patterns Knowledge Points</description></item><item><title>Js singleton pattern</title><link>https://yosgi.github.io/en/post/js-singleton-pattern/</link><pubDate>Fri, 13 Apr 2018 20:06:30 +1200</pubDate><guid>https://yosgi.github.io/en/post/js-singleton-pattern/</guid><description>Javascript Design Patterns Knowledge Points</description></item><item><title>Function extension</title><link>https://yosgi.github.io/en/post/function-extension/</link><pubDate>Thu, 12 Apr 2018 00:00:00 +1200</pubDate><guid>https://yosgi.github.io/en/post/function-extension/</guid><description>"ES6 Standard Introduction" Knowledge Points Summary</description></item><item><title>Array expansion</title><link>https://yosgi.github.io/en/post/array-expansion/</link><pubDate>Wed, 11 Apr 2018 00:00:00 +1200</pubDate><guid>https://yosgi.github.io/en/post/array-expansion/</guid><description>"ES6 Standard Introduction" Knowledge Points Summary</description></item><item><title>Destructuring assignment of variables</title><link>https://yosgi.github.io/en/post/destructuring-assignment-of-variables/</link><pubDate>Tue, 10 Apr 2018 11:07:34 +1200</pubDate><guid>https://yosgi.github.io/en/post/destructuring-assignment-of-variables/</guid><description>"ES6 Standard Introduction" Knowledge Points Summary</description></item></channel></rss>