-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalphabetics.js
More file actions
34 lines (30 loc) · 1.11 KB
/
Copy pathalphabetics.js
File metadata and controls
34 lines (30 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// 12. Write a JavaScript function that returns a passed string with letters in alphabetical order.
/*
steps:
01:Split the string into an array of characters using split() method.
02:Apply the sort() method to sort the characters in alphabetical order.
03:Finally, we use the join() method to join the characters back into a string.
*/
function alphaOrder(str) {
// 01:Split the string into an array of characters using split() method.
let arr = str.split("");
// 02:Apply the sort() method to sort the characters in alphabetical order.
arr.sort();
// 03:Finally, we use the join() method to join the characters back into a string.
let sortedStr = arr.join("");
return sortedStr;
}
console.log(alphaOrder("ikram akbar"));
// ===================================================
function alphabet(strings) {
if (strings == null || strings == Number) {
console.log("please insert only string");
} else {
let newArr = strings.split("");
newArr.sort();
let sortedStrings = newArr.join("");
return sortedStrings;
}
}
// console.log(alphabet("ikram akbar"));
console.log(alphabet(454545));