Platform
Resources
Pricing
Sign in
Get started
Emir Salazar
Workspace
Fork
Published
By
Emir Salazar
Edited
Oct 14, 2020
Insert cell
Insert cell
function
reverse
(
arr
)
{
// Other way is to use reduce right
// return arr.reduceRight((a, e) => [...a, e], []);
return
Array
.
from
(
arr
,
(
e
,
i
)
=>
arr
[
arr
.
length
-
1
-
i
]
)
;
}
Insert cell
reverse
(
[
4
,
5
,
6
]
)
Insert cell
function
reverseStr
(
str
)
{
// return str
// .match(/\w+|\s/g)
// .reverse()
// .join('');
return
str
.
match
(
/\w+|\s?/g
)
.
reduceRight
(
(
a
,
b
)
=>
[
...
a
,
b
]
,
[
]
)
.
join
(
''
)
;
}
Insert cell
reverseStr
(
'Hello world this'
)
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
reverse
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
reverseStr
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML