-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTakseer.js
More file actions
34 lines (34 loc) · 863 Bytes
/
Copy pathTakseer.js
File metadata and controls
34 lines (34 loc) · 863 Bytes
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
function takseer(string) {
let result = ""
string = string.replaceAll(" ", "")
let stringLength = string.length
let last = stringLength - 1
if (stringLength % 2 == 0) {
for (let i = 0; i < stringLength / 2; i++) {
result = result.concat(string[i])
result = result.concat(string[last])
last--
}
} else {
stringLength = stringLength - 1
for (let i = 0; i < stringLength / 2; i++) {
result = result.concat(string[i])
result = result.concat(string[last])
last--
if (i == stringLength / 2 - 1) {
result = result.concat(string[i + 1])
}
}
}
arr.push(result)
console.log(result)
if (result !== check) {
takseer(arr.at(-1))
}
}
const arr = []
var string = prompt("Enter value")
arr.push(string)
let arr1 = arr[0]
var check = arr1.replaceAll(" ", "")
takseer(arr.at(-1))