In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about the usefulness of the javascript shift () method. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
In javascript, the shift () method deletes the first element of the array, returns the value of the first element, and then moves all remaining elements forward one bit to fill the gap in the array header; the syntax "array.shift ()".
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
The shift () method deletes the first element of the array, returns it, and then moves all remaining elements forward one bit to fill the gap in the array header. If the array is empty, shift () does nothing and returns undefined.
Syntax: array.shift ()
Return value: the value of the original first element of the array (removed element), which can be of any type (because the array element can be a string, number, array, Boolean, or other object type).
Example:
Var a = [1, console.log 2, 3, 4, 5, 6, 7, 8]; / / define the array a.shift (); console.log (a)
A classic programming game is attached: a group of monkeys are lined up in a circle and numbered by 1, 2, 3,., n. Then count it from finger 1, count to m, kick it out of the circle, then start counting from behind it, when you count m again, continue to kick it out, and so on, until there is only one monkey left, that monkey is called the king. Require programming to simulate this process, enter m, n to output the number of the last king.
/ / n indicates the number of monkeys, m indicates the proposed position function f (mrecoery n) {/ / number the monkeys and put them into the array var arr = []; for (I = 1; I
< n+1; i ++) { arr.push(i); } //当数组内只剩下一只猴子时跳出循环 while (arr.length >1) {for (var I = 0; I
< m-1; i ++) { //定义排队轮转的次数 arr.push(arr.shift()); //队列操作,完成猴子的轮转 } arr.shift(); //提出第m只猴子 } return arr; //返回包含最后一只猴子的数组}console.log(f(5,3)); //编号为4的猴子胜出The above is what is the use of the javascript shift () method shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
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.