Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

42%
+1 −2
Q&A How do I filter an array in C?

No, I'm not trying to get the full program written completely in C by you guys. I only need some way to implement the functionalities of each function I found confusing. In this challenge in Code ...

2 answers  ·  posted 2y ago by General Sebast1an‭  ·  last activity 2y ago by Derek Elkins‭

Question c javascript array
#7: Post undeleted by user avatar General Sebast1an‭ · 2021-08-28T13:34:41Z (over 2 years ago)
#6: Post deleted by user avatar General Sebast1an‭ · 2021-08-28T08:24:19Z (over 2 years ago)
#5: Post edited by user avatar Moshi‭ · 2021-08-28T01:25:39Z (over 2 years ago)
Focused the title
  • What's an equivalent implementation of this JavaScript program?
  • How do I filter an array in C?
No, I'm not trying to get the full program written completely in C by you guys. I only need some way to implement the functionalities of each function I found confusing.

In [this challenge in Code Golf CD](https://codegolf.codidact.com/posts/283789), I have to make a program that computes the determinant of a two-dimensional array. It also has a program written in JavaScript that solves the challenge which looks like this:
```js
function laplaceDet(matrix) {
	if (matrix.length === 1) return matrix[0][0];

	let sum = 0;
	for (let rowIndex = 0; rowIndex < matrix.length; ++rowIndex) {
		let minorMatrix = matrix.filter((_, index) => index !== rowIndex)
			          .map(row => row.slice(1));
		sum += ((-1) ** rowIndex) * matrix[rowIndex][0] * laplaceDet(minorMatrix);
	}
	return sum;
}
```

I want to challenge myself into using C for solving the challenge. First, I'll need to reimplement the program, whereas the golfing part will be dealt with later, although I've already been golfing it. [Here's what I got so far.](https://tio.run/##HYvLCsMgEEXX@hUux0egWVu/JHQxhEwZG7SopYuSbzexcDmcxbnrtO6Ynr2zi56A9oxNGYOOU1NV/6RgghrCPFSUrX1KUrjcHte8FAflAp7v1bO1/ySGCy8b3vkL0@xYG1x41IYg6nGRR@8n)

Why'd I stop? There's a function named `filter()` and I'm not so sure how to get it implemented, and since C has no maps (at least I think none exist in C), it's also difficult to complete the program without it.

So I'll have to improvise... How? How do I implement the `filter()` method, maybe without using a function to save bytes, and what's a C equivalent to the line of code `matrix.filter((_, index) => index !== rowIndex).map(row => row.slice(1));`?
#4: Post edited by user avatar General Sebast1an‭ · 2021-08-28T01:15:48Z (over 2 years ago)
  • No, I'm not trying to get the full program written completely in C by you guys. I only need some way to implement the functionalities of each function I found confusing.
  • In [this challenge in Code Golf CD](https://codegolf.codidact.com/posts/283789), I have to make a program that computes the determinant of a two-dimensional array. It also has a program written in JavaScript that solves the challenge which looks like this:
  • ```js
  • function laplaceDet(matrix) {
  • if (matrix.length === 1) return matrix[0][0];
  • let sum = 0;
  • for (let rowIndex = 0; rowIndex < matrix.length; ++rowIndex) {
  • let minorMatrix = matrix.filter((_, index) => index !== rowIndex)
  • .map(row => row.slice(1));
  • sum += ((-1) ** rowIndex) * matrix[rowIndex][0] * laplaceDet(minorMatrix);
  • }
  • return sum;
  • }
  • ```
  • I want to challenge myself into using C for solving the challenge. First, I'll need to reimplement the program, whereas the golfing part will be dealt with later, although I've already been golfing it. [Here's what I got so far.](https://tio.run/##S9ZNzknMS///P1MnSyfbOk0jLSc/sURBSytRJzOvRKFYs5qLMzNNo9jW1hDE5CxKLSktylNIjDaIBSJrLs7atPwiDetMm2LrTG1tsBKgGFft//8A)
  • Why'd I stop? There's a function named `filter()` and I'm not so sure how to get it implemented, and since C has no maps (at least I think none exist in C), it's also difficult to complete the program without it.
  • So I'll have to improvise... How? How do I implement the `filter()` method, maybe without using a function to save bytes, and what's a C equivalent to the line of code `matrix.filter((_, index) => index !== rowIndex).map(row => row.slice(1));`?
  • No, I'm not trying to get the full program written completely in C by you guys. I only need some way to implement the functionalities of each function I found confusing.
  • In [this challenge in Code Golf CD](https://codegolf.codidact.com/posts/283789), I have to make a program that computes the determinant of a two-dimensional array. It also has a program written in JavaScript that solves the challenge which looks like this:
  • ```js
  • function laplaceDet(matrix) {
  • if (matrix.length === 1) return matrix[0][0];
  • let sum = 0;
  • for (let rowIndex = 0; rowIndex < matrix.length; ++rowIndex) {
  • let minorMatrix = matrix.filter((_, index) => index !== rowIndex)
  • .map(row => row.slice(1));
  • sum += ((-1) ** rowIndex) * matrix[rowIndex][0] * laplaceDet(minorMatrix);
  • }
  • return sum;
  • }
  • ```
  • I want to challenge myself into using C for solving the challenge. First, I'll need to reimplement the program, whereas the golfing part will be dealt with later, although I've already been golfing it. [Here's what I got so far.](https://tio.run/##HYvLCsMgEEXX@hUux0egWVu/JHQxhEwZG7SopYuSbzexcDmcxbnrtO6Ynr2zi56A9oxNGYOOU1NV/6RgghrCPFSUrX1KUrjcHte8FAflAp7v1bO1/ySGCy8b3vkL0@xYG1x41IYg6nGRR@8n)
  • Why'd I stop? There's a function named `filter()` and I'm not so sure how to get it implemented, and since C has no maps (at least I think none exist in C), it's also difficult to complete the program without it.
  • So I'll have to improvise... How? How do I implement the `filter()` method, maybe without using a function to save bytes, and what's a C equivalent to the line of code `matrix.filter((_, index) => index !== rowIndex).map(row => row.slice(1));`?
#3: Post edited by user avatar General Sebast1an‭ · 2021-08-28T01:10:14Z (over 2 years ago)
  • No, I'm not trying to get the full program written completely in C by you guys. I only need some way to implement the functionalities of each function I found confusing.
  • In [this challenge in Code Golf CD](https://codegolf.codidact.com/posts/283789), I have to make a program that computes the determinant of a two-dimensional array. It also has a program written in JavaScript that solves the challenge which looks like this:
  • ```js
  • function laplaceDet(matrix) {
  • if (matrix.length === 1) return matrix[0][0];
  • let sum = 0;
  • for (let rowIndex = 0; rowIndex < matrix.length; ++rowIndex) {
  • let minorMatrix = matrix.filter((_, index) => index !== rowIndex)
  • .map(row => row.slice(1));
  • sum += ((-1) ** rowIndex) * matrix[rowIndex][0] * laplaceDet(minorMatrix);
  • }
  • return sum;
  • }
  • ```
  • I want to challenge myself into using C for solving the challenge. First, I'll need to reimplement the program, whereas the golfing part will be dealt with later, although I've already been golfing it. [Here's what I got so far.](https://tio.run/##S9ZNzknMS///P1MnSyfbOk0jUbOaizPLtjizKjUfxNOHsjLzSjS5ODPTNLJsbQ1BajiLUktKi/IUEqMNYoHImouzNi2/SMM60ybLOlNbG6wEKMZV@/8/AA "C (clang) – Try It Online")
  • Why'd I stop? There's a function named `filter()` and I'm not so sure how to get it implemented, and since C has no maps (at least I think none exist in C), it's also difficult to complete the program without it.
  • So I'll have to improvise... How? How do I implement the `filter()` method, maybe without using a function to save bytes, and what's a C equivalent to the line of code `matrix.filter((_, index) => index !== rowIndex).map(row => row.slice(1));`?
  • No, I'm not trying to get the full program written completely in C by you guys. I only need some way to implement the functionalities of each function I found confusing.
  • In [this challenge in Code Golf CD](https://codegolf.codidact.com/posts/283789), I have to make a program that computes the determinant of a two-dimensional array. It also has a program written in JavaScript that solves the challenge which looks like this:
  • ```js
  • function laplaceDet(matrix) {
  • if (matrix.length === 1) return matrix[0][0];
  • let sum = 0;
  • for (let rowIndex = 0; rowIndex < matrix.length; ++rowIndex) {
  • let minorMatrix = matrix.filter((_, index) => index !== rowIndex)
  • .map(row => row.slice(1));
  • sum += ((-1) ** rowIndex) * matrix[rowIndex][0] * laplaceDet(minorMatrix);
  • }
  • return sum;
  • }
  • ```
  • I want to challenge myself into using C for solving the challenge. First, I'll need to reimplement the program, whereas the golfing part will be dealt with later, although I've already been golfing it. [Here's what I got so far.](https://tio.run/##S9ZNzknMS///P1MnSyfbOk0jLSc/sURBSytRJzOvRKFYs5qLMzNNo9jW1hDE5CxKLSktylNIjDaIBSJrLs7atPwiDetMm2LrTG1tsBKgGFft//8A)
  • Why'd I stop? There's a function named `filter()` and I'm not so sure how to get it implemented, and since C has no maps (at least I think none exist in C), it's also difficult to complete the program without it.
  • So I'll have to improvise... How? How do I implement the `filter()` method, maybe without using a function to save bytes, and what's a C equivalent to the line of code `matrix.filter((_, index) => index !== rowIndex).map(row => row.slice(1));`?
#2: Post edited by user avatar General Sebast1an‭ · 2021-08-27T22:42:25Z (over 2 years ago)
  • No, I'm not trying to get the full program written completely in C by you guys. I only need some way to implement the functionalities of each function I found confusing.
  • In [this challenge in Code Golf CD](https://codegolf.codidact.com/posts/283789), I have to make a program that computes the determinant of a two-dimensional array. It also has a program written in JavaScript that solves the challenge which looks like this:
  • ```js
  • function laplaceDet(matrix) {
  • if (matrix.length === 1) return matrix[0][0];
  • let sum = 0;
  • for (let rowIndex = 0; rowIndex < matrix.length; ++rowIndex) {
  • let minorMatrix = matrix.filter((_, index) => index !== rowIndex)
  • .map(row => row.slice(1));
  • sum += ((-1) ** rowIndex) * matrix[rowIndex][0] * laplaceDet(minorMatrix);
  • }
  • return sum;
  • }
  • ```
  • I want to challenge myself into using C for solving the challenge. First, I'll need to reimplement the program, whereas the golfing part will be dealt with later, although I've already been golfing it. [Here's what I got so far.](https://tio.run/##S9ZNzknMS///P1MnSyfbOk0jUbOaizPLtjizKjUfxNOHsjLzSjS5ODPTNLJsbQ1BajiLUktKi/IUEqMNYoHImouzNi2/SMM60ybLOlNbG6wEKMZV@/8/AA "C (clang) – Try It Online")
  • <div style="color:red">Why'd I stop?</div> There's a function named `filter()` and I'm not so sure how to get it implemented, and since C has no maps (at least I think none exist in C), it's also difficult to complete the program without it.
  • So I'll have to improvise... How? How do I implement the `filter()` method, maybe without using a function to save bytes, and what's a C equivalent to the line of code `matrix.filter((_, index) => index !== rowIndex).map(row => row.slice(1));`?
  • No, I'm not trying to get the full program written completely in C by you guys. I only need some way to implement the functionalities of each function I found confusing.
  • In [this challenge in Code Golf CD](https://codegolf.codidact.com/posts/283789), I have to make a program that computes the determinant of a two-dimensional array. It also has a program written in JavaScript that solves the challenge which looks like this:
  • ```js
  • function laplaceDet(matrix) {
  • if (matrix.length === 1) return matrix[0][0];
  • let sum = 0;
  • for (let rowIndex = 0; rowIndex < matrix.length; ++rowIndex) {
  • let minorMatrix = matrix.filter((_, index) => index !== rowIndex)
  • .map(row => row.slice(1));
  • sum += ((-1) ** rowIndex) * matrix[rowIndex][0] * laplaceDet(minorMatrix);
  • }
  • return sum;
  • }
  • ```
  • I want to challenge myself into using C for solving the challenge. First, I'll need to reimplement the program, whereas the golfing part will be dealt with later, although I've already been golfing it. [Here's what I got so far.](https://tio.run/##S9ZNzknMS///P1MnSyfbOk0jUbOaizPLtjizKjUfxNOHsjLzSjS5ODPTNLJsbQ1BajiLUktKi/IUEqMNYoHImouzNi2/SMM60ybLOlNbG6wEKMZV@/8/AA "C (clang) – Try It Online")
  • Why'd I stop? There's a function named `filter()` and I'm not so sure how to get it implemented, and since C has no maps (at least I think none exist in C), it's also difficult to complete the program without it.
  • So I'll have to improvise... How? How do I implement the `filter()` method, maybe without using a function to save bytes, and what's a C equivalent to the line of code `matrix.filter((_, index) => index !== rowIndex).map(row => row.slice(1));`?
#1: Initial revision by user avatar General Sebast1an‭ · 2021-08-27T22:41:52Z (over 2 years ago)
What's an equivalent implementation of this JavaScript program?
No, I'm not trying to get the full program written completely in C by you guys. I only need some way to implement the functionalities of each function I found confusing.

In [this challenge in Code Golf CD](https://codegolf.codidact.com/posts/283789), I have to make a program that computes the determinant of a two-dimensional array. It also has a program written in JavaScript that solves the challenge which looks like this:
```js
function laplaceDet(matrix) {
	if (matrix.length === 1) return matrix[0][0];

	let sum = 0;
	for (let rowIndex = 0; rowIndex < matrix.length; ++rowIndex) {
		let minorMatrix = matrix.filter((_, index) => index !== rowIndex)
			          .map(row => row.slice(1));
		sum += ((-1) ** rowIndex) * matrix[rowIndex][0] * laplaceDet(minorMatrix);
	}
	return sum;
}
```

I want to challenge myself into using C for solving the challenge. First, I'll need to reimplement the program, whereas the golfing part will be dealt with later, although I've already been golfing it. [Here's what I got so far.](https://tio.run/##S9ZNzknMS///P1MnSyfbOk0jUbOaizPLtjizKjUfxNOHsjLzSjS5ODPTNLJsbQ1BajiLUktKi/IUEqMNYoHImouzNi2/SMM60ybLOlNbG6wEKMZV@/8/AA "C (clang) – Try It Online")

<div style="color:red">Why'd I stop?</div> There's a function named `filter()` and I'm not so sure how to get it implemented, and since C has no maps (at least I think none exist in C), it's also difficult to complete the program without it.

So I'll have to improvise... How? How do I implement the `filter()` method, maybe without using a function to save bytes, and what's a C equivalent to the line of code `matrix.filter((_, index) => index !== rowIndex).map(row => row.slice(1));`?