如果我有一组对象和一个 JavaScript 对象:
var data = [{"a": 1, "b": 2}, {"a": 1}, {"a": 1, "b": 2, "c": 3}];
var myFilter = {"a": 1, "b": 2};
Run Code Online (Sandbox Code Playgroud)
...并且希望使用myFilter对象作为对象数组的过滤器来创建新的对象数组,当且仅当该对象至少匹配或包含myFilter键/值对。
任何建议我如何继续并将其放入代码中?我需要创建一个data使用myFilter键/值对过滤的新数组。
我能够做到这一点,但myFilter只包含 1 个键/值对。
我预期的新数组是:
var newArr = [];
newArr = [{"a": 1, "b": 2}, {"a": 1, "b": 2, "c": 3}];
Run Code Online (Sandbox Code Playgroud) #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char line[80];
FILE *in = fopen("spooky.csv", "r");
FILE *file1 = fopen("ufos.csv", "w");
FILE *file2 = fopen("disappearances.csv", "w");
FILE *file3 = fopen("others.csv", "w");
while (fscanf(in, "%79[^\n]\n", line) == 1) {
if (strstr(line, "UFO"))
fprintf(file1, "%s\n", line);
else if (strstr(line, "Disappearance"))
fprintf(file2, "%s\n", line);
else
fprintf(file3, "%s\n", line);
}
fclose(file1);
fclose(file2);
fclose(file3);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
此代码返回分段错误的运行时错误。
我在什么硬件上编译这个程序有关系吗?我使用的是带有 Intel Core i7(第七代)的 Fedora 38(工作站)。