Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4e6190b

Browse files
authored
Merge pull requestneetcode-gh#2006 from AkifhanIlgaz/1472
Create: 1472-design-browser-history.rs / .ts / .js / .go
2 parentsdda0e03 +3e71fc9 commit4e6190b

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed

‎go/1472-design-browser-history.go‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package main
2+
3+
import"math"
4+
5+
funcmain() {
6+
7+
}
8+
9+
typeBrowserHistorystruct {
10+
history []string
11+
currentint
12+
}
13+
14+
funcConstructor(homepagestring)BrowserHistory {
15+
returnBrowserHistory{
16+
history: []string{homepage},
17+
current:0,
18+
}
19+
}
20+
21+
func (this*BrowserHistory)Visit(urlstring) {
22+
this.history=this.history[0:this.current+1]
23+
this.history=append(this.history,url)
24+
this.current++
25+
}
26+
27+
func (this*BrowserHistory)Back(stepsint)string {
28+
this.current=int(math.Max(float64(this.current)-float64(steps),0))
29+
returnthis.history[this.current]
30+
}
31+
32+
func (this*BrowserHistory)Forward(stepsint)string {
33+
this.current=int(math.Min(float64(this.current)+float64(steps),float64(len(this.history)-1)))
34+
returnthis.history[this.current]
35+
}
36+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
classBrowserHistory{
2+
constructor(homepage){
3+
this.history=[homepage];
4+
this.current=0;
5+
}
6+
7+
/**
8+
*@param {string} url
9+
*@return {void}
10+
*/
11+
12+
visit(url){
13+
this.history[++this.current]=url;
14+
this.history.length=this.current+1;
15+
}
16+
17+
/**
18+
*@param {number} steps
19+
*@return {string}
20+
*/
21+
back(steps){
22+
this.current=Math.max(this.current-steps,0);
23+
returnthis.history[this.current];
24+
}
25+
26+
/**
27+
*@param {number} steps
28+
*@return {string}
29+
*/
30+
forward(steps){
31+
this.current=Math.min(this.current+steps,this.history.length-1);
32+
returnthis.history[this.current];
33+
}
34+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
structBrowserHistory{
2+
history:Vec<String>,
3+
current:usize,
4+
}
5+
6+
implBrowserHistory{
7+
fnnew(homepage:String) ->Self{
8+
Self{
9+
history:vec![homepage],
10+
current:0,
11+
}
12+
}
13+
14+
fnvisit(&mutself,url:String){
15+
self.current +=1;
16+
self.history.splice(self.current.., std::iter::once(url));
17+
}
18+
19+
fnback(&mutself,steps:i32) ->String{
20+
self.current =self.current.saturating_sub(stepsasusize);
21+
self.history[self.current].clone()
22+
}
23+
24+
fnforward(&mutself,steps:i32) ->String{
25+
self.current =(self.current + stepsasusize).min(self.history.len() -1);
26+
self.history[self.current].clone()
27+
}
28+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
classBrowserHistory{
2+
history:string[];
3+
current:number;
4+
5+
constructor(homepage:string){
6+
this.history=[homepage];
7+
this.current=0;
8+
}
9+
10+
visit(url:string):void{
11+
this.history[++this.current]=url;
12+
this.history.length=this.current+1;
13+
}
14+
15+
back(steps:number):string{
16+
this.current=Math.max(this.current-steps,0);
17+
returnthis.history[this.current];
18+
}
19+
20+
forward(steps:number):string{
21+
this.current=Math.min(this.current+steps,this.history.length-1);
22+
returnthis.history[this.current];
23+
}
24+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp