JavaScript:充满范围的新数组

时间:2018-09-11 20:25:31

标签: javascript

我正在尝试创建一个自动填充特定值范围的新数组。我正在尝试使用巧妙的代码来实现这一目标。

char*

到目前为止,我最好的主意如下:

Removing3.c:12:8: warning: incompatible integer to pointer conversion initializing 'char *' with an
      expression of type 'char'; remove * [-Wint-conversion]
        char *charTest2 = *argv[2];
              ^           ~~~~~~~~
Removing3.c:30:20: warning: comparison between pointer and integer ('int' and 'char *')
        pw += (*pw != c);
               ~~~ ^  ~
2 warnings generated.

我上面的想法是,我使用散布运算符将数组Removing3.c:18:19: warning: incompatible integer to pointer conversion passing 'char' to parameter of type 'char *'; take the address with & [-Wint-conversion] remove_all_chars(strTest, charTest2); ^~~~~~~ & Removing3.c:2:29: note: passing argument to parameter here void remove_all_chars(char *, char *); ^ Removing3.c:18:28: warning: incompatible integer to pointer conversion passing 'char' to parameter of type 'char *'; take the address with & [-Wint-conversion] remove_all_chars(strTest, charTest2); ^~~~~~~~~ & Removing3.c:2:37: note: passing argument to parameter here void remove_all_chars(char *, char *); ^ Removing3.c:19:15: warning: format specifies type 'char *' but the argument has type 'char' [-Wformat] printf("%s", strTest); ~~ ^~~~~~~ %c Removing3.c:30:20: warning: comparison between pointer and integer ('int' and 'char *') pw += (*pw != c); ~~~ ^ ~ 4 warnings generated. 填充为一个n值的新鲜数组,这需要足够的空间来大于范围之差。然后,我使用JS // MainApplication ... import android.content.Context; import android.support.multidex.MultiDex; ... public class MainApplication extends Application implements ReactApplication { ... @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(getBaseContext()); } } 方法仅返回适合if Example given range: 1995 to 2020 Sample Output: [1995, 1996, 1997, ..., 2020] 的三元表达式的值,然后返回范围加n的开始,所以years = [...new Array(100).filter((_, n) => (1995 + n) != 2020 ? 1995 + n : 2020)];

这里有什么想法吗?我正在尝试避免编写某些函数或巨型years循环,并将其保持在机智的衬里之上。感谢您的帮助!

进行编辑,以便主持人解锁问题,以便我发布解决方案。

0 个答案:

没有答案