Skip to content

Commit

Permalink
задача 'asc' или 'desc'
Browse files Browse the repository at this point in the history
  • Loading branch information
TimofeevAnton1980 committed Nov 6, 2024
1 parent df05c5c commit 8e431f6
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions 02-javascript-data-types/1-sort-strings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@
* @param {string} [param="asc"] param - the sorting type "asc" or "desc"
* @returns {string[]}
*/
export function sortStrings(arr, param = 'asc') {

export function sortStrings(arr, param = "asc") {
if (param !== "asc" && param !== "desc") {
throw new Error("Должно быть 'asc' или 'desc'");
}
return arr.slice().sort((a, b) => {
if (param === "asc") {
return a.localeCompare(b, undefined, {
sensitivity: "variant",
caseFirst: "upper",
});
} else {
return b.localeCompare(a, undefined, {
sensitivity: "variant",
caseFirst: "upper",
});
}
});
}

0 comments on commit 8e431f6

Please sign in to comment.