Platform
Resources
Pricing
Sign in
Get started
Francois Laberge
Web Developer, Roboticist, Programming Language Enthusiast, Ex Game Dev, Tools Developer, and Canadian
Workspace
Fork
Public
By
Francois Laberge
Edited
May 11, 2023
Insert cell
Insert cell
str
=
'\n00000000: 0 -65536 0\n00000001: 65536 0 0\n00000002: 0 44695552 1073741824\n'
Insert cell
function
parseDisplayMatrix
(
str
)
{
const
regex
=
/\d+:\s+([-+]?\d+)\s+([-+]?\d+)\s+([-+]?\d+)/g
;
let
a
=
str
.
match
(
regex
)
;
let
b
=
str
.
match
(
regex
)
;
let
c
=
str
.
match
(
regex
)
;
return
{
a
,
b
,
c
}
;
}
Insert cell
parseDisplayMatrix
(
str
)
Insert cell
{
// const regex = /\d+/g; // Regular expression to match stringified numbers
const
regex
=
/^\d+:\s+([-+]?\d+)\s+([-+]?\d+)\s+([-+]?\d+)$/gm
;
const
input
=
str
;
const
matches
=
[
]
;
let
match
;
while
(
(
match
=
regex
.
exec
(
input
)
)
)
{
const
number
=
parseInt
(
match
[
0
]
,
10
)
;
// Convert the matched element to a number
matches
.
push
(
number
)
;
}
return
matches
;
}
Insert cell
{
const
numbers
=
str
.
match
(
/[-+]?\d+/g
)
?.
map
(
Number
)
||
[
]
;
const
[
,
m00
,
m10
,
,
,
m01
,
m11
,
,
,
m02
,
m12
]
=
numbers
;
return
[
m00
,
m10
,
m01
,
m11
]
.
map
(
(
e
)
=>
e
/
65536
)
;
}
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
str
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
parseDisplayMatrix
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML