Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F9583998
integer-cartesian.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
integer-cartesian.js
View Options
"use strict"
;
const
clone
=
require
(
"clone"
);
const
IntegerCartesian
=
{
// integer-only
next
:
function
(
sources
,
element
)
{
for
(
const
i
in
sources
)
{
if
(
sources
[
i
]
<=
0
)
{
return
null
;
}
}
const
new_element
=
clone
(
element
);
if
(
element
===
null
)
{
return
sources
.
map
(()
=>
0
);
}
else
{
let
i
=
element
.
length
-
1
;
while
(
i
>=
0
)
{
if
(
element
[
i
]
>=
sources
[
i
])
{
throw
new
Error
(
`Invalid element. Max value on index '
${
i
.
toString
()
}
' is '
${
(
sources
[
i
]
-
1
).
toString
()
}
'`
);
}
if
(
element
[
i
]
===
sources
[
i
]
-
1
)
{
new_element
[
i
]
=
0
;
}
else
{
break
;
}
i
--
;
}
if
(
i
===
-
1
)
{
return
null
;
}
new_element
[
i
]
=
new_element
[
i
]
+
1
;
return
new_element
;
}
},
};
module
.
exports
=
IntegerCartesian
;
/*
//simple tests
console.log(Cartesian.next([3, 2], null)); // [0,0]
console.log(Cartesian.next([3, 2], [0,0]));
console.log(Cartesian.next([3, 2], [0,1]));
console.log(Cartesian.next([3, 2], [1,0]));
console.log(Cartesian.next([3, 2], [1,1]));
console.log(Cartesian.next([3, 2], [2,0]));
console.log(Cartesian.next([3, 2], [2, 1])); //null
*/
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Oct 11, 11:19 (12 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
982136
Default Alt Text
integer-cartesian.js (1 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment