In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "JavaScript how to find the sum of two numbers", the content of the explanation is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "JavaScript how to find the sum of two numbers" bar!
JavaScript's method of finding the sum of two numbers: [const method2 = (start: number, end: number) = > {return ((end-start + 1) * (start + end)) / 2}].
This article operating environment: windows10 system, javascript 1.8.5, thinkpad T480 computer.
Calculate the cumulative sum of two positive integers
The specific code is as follows:
/ * * @ description for loop * @ param start start * @ param end end * / const method1 = (start: number, end: number) = > {/ / if start is greater than end direct return if (start > end) {return;} let sum = 0; for (let I = start; I {return ((end-start + 1) * (start + end)) / 2;} / * * @ description Recursive algorithm * @ param start * @ param end * / const method3 = (start: number, end: number) = > {if (start > end) {return;} else {if (end > start) {return end + method3 (start, end-1);} else {return start}; console.log (method1 (8,100)); / / 5022console.log (method3 (8,100)) / / 5022console.log (method2 (8100)); / / 5022 Thank you for your reading. The above is the content of "how to find the sum of two numbers in JavaScript". After the study of this article, I believe you have a deeper understanding of how to find the sum of two numbers in JavaScript, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.