-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Добавил сохранение истории городов между запусками
- Loading branch information
1 parent
04ce289
commit 51b73e8
Showing
3 changed files
with
53 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
function setToString(set) { | ||
let str = ""; | ||
set.forEach((value) => { | ||
str += `${value} `; | ||
}); | ||
return str.trim(); | ||
} | ||
|
||
function stringToSet(string) { | ||
const set = new Set(); | ||
string.split(" ").forEach((value) => { | ||
set.add(value); | ||
}); | ||
return set; | ||
} | ||
|
||
export function getHistorySet() { | ||
let historySet = new Set(); | ||
const historyString = localStorage.getItem("history"); | ||
if (historyString !== null && historyString.length > 0) { | ||
historySet = stringToSet(historyString); | ||
} | ||
return historySet; | ||
} | ||
|
||
export function setHistorySet(historySet) { | ||
localStorage.setItem("history", setToString(historySet)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters