在以下简短脚本中(在我的浏览器中运行):
var ages = [23, 22, 4, 101, 14, 78, 90, 2, 1, 89, 19];
const ages3 = ages.map(function(age) {
return Math.sqrt(age) + "<br/>";
});
document.write(ages3);Run Code Online (Sandbox Code Playgroud)
我想以最简洁的方式打印一列平方根值(最好使用上面的 map 方法)。我试图链接一个连接,例如,return age.join(' ').Math.sqrt(age) + "<br/>"; but that was unsuccessful (no output was produced).
谢谢你。
我最近开始探索 Nim 编程语言,我想知道如何连接到 SQLite 数据库。阅读手册的相关部分后,我的困惑并没有减少。如果有人愿意提供一个简单的例子,我将不胜感激。
谢谢。
我对这样一个基本的问题表示歉意,但我正在尝试使用 awk 计算文本文件中的空白行数。这不是家庭作业。Windows 10.Gawk 4.1.3
BEGIN { x=0 }
/^$/ { x=x+1 }
END { print "I found " x " blank lines." }
Run Code Online (Sandbox Code Playgroud)
输出始终是:我发现 0 个空行。
谢谢。
每当我尝试使用“ Gadfly”,“ Bio”或其他几个软件包(在示例中使用“ Bio”)时,都会出现以下消息:
julia> using Bio
INFO: Recompiling stale cache file C:\Users\CaitlinG\emacs251\.julia\lib\v0.5\Di
stributions.ji for module Distributions.
INFO: Recompiling stale cache file C:\Users\CaitlinG\emacs251\.julia\lib\v0.5\Bi
o.ji for module Bio.
Run Code Online (Sandbox Code Playgroud)
Julia 0.5.1(已更新所有套件)Windows 10(已全面更新)Emacs 25.1
这很不方便,因为我只能假定它不是导入软件包的“典型”组件。删除.julia目录可以解决此问题吗?
谢谢。
我不明白为什么以下lisp程序显示15行而不是10行:
(defparameter x 1)
(dotimes (x 10)
(if (oddp x)
(format t "x is odd~%"))
(format t "x is even~%"))
Run Code Online (Sandbox Code Playgroud)
我在Windows 10计算机上使用CLISP 2.49。
以下代码:
(into {} [[:a 1][:b 2][:c 3][:d 4][:e 5]])
Run Code Online (Sandbox Code Playgroud)
...生成关键字/值对的映射(?).我不太明白双方括号的意义,我假设它是一个解构的例子?
谢谢,
〜凯特琳
我正在自学“D”,我有一个关于模板的问题,对某些人来说可能看起来很基本。例如,我目前正在阅读的文章(请参阅本文底部)包含以下代码:
int foo(int x)
{
return x;
}
string foo(string x)
{
return x;
}
void main()
{
assert(foo(12345) == 12345);
assert(foo("hello") == "hello");
}
Run Code Online (Sandbox Code Playgroud)
显然,这个特定的片段不够优雅,模板将消除重复:
foo(T)(T x)
{
return x;
}
void main()
{
assert(foo!(int)(12345) == 12345);
assert(foo!(string)("hello") == "hello");
}
Run Code Online (Sandbox Code Playgroud)
The second example is rather basic since we are merely returning the value passed. My confusion arises by the fact that the function, however templated, still appears to be constrained to one type of value since I cannot …
这不是家庭作业。在下面的代码中:
(defparameter nums '())
(defun fib (number)
(if (< number 2)
number
(push (+ (fib (- number 1)) (fib (- number 2))) nums))
return nums)
(format t "~a " (fib 100))
Run Code Online (Sandbox Code Playgroud)
由于我对Common Lisp完全没有经验,所以我对为什么该函数不返回值感到困惑。我正在尝试打印斐波那契数列的第一个“ n”值,例如100。
谢谢。
由于在Java中实现接口的类必须定义接口中的每个方法以避免被声明为抽象,我想知道以下内容:
当我创建一个实例化Hashtable对象的程序时,为什么我不需要在Map接口中定义每个方法?我没有明确定义的方法是自动创建的"存根"吗?
这纯粹是出于自身利益而不是家庭作业.
#include <stdio.h>
int main(void)
{
char* str3;
char* str1 = "Hello";
char* str2 = "World!";
while(*str1) str1++;
while(*str1++ = *str2++);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我试图更好地理解C指针,并且这样做我想连接两个字符串并将结果放入第三个字符串.上面的(不完整的)代码会导致段错误,我不知道为什么.是不是可以循环指针引用的值并将数据复制到另一个地址?
编辑:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
char* str1 = "Hello";
char* str2 = "World!";
char *str3 = malloc(strlen(str1) + strlen(str2) + 1);
while(*str1) *str3++ = *str1++;
while(*str2) *str3++ = *str2++;
puts(str3);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
新的尝试是在上面,虽然不起作用,但是我需要修复"明显"的项目吗?
我试图将以下Haskell代码移植到Python中,我正在接受"无效语法"响应.
let rightTriangles' = [ (a,b,c) | c <- [1..10], b <- [1..c], a <- [1..b], a^2 + b^2 == c^2, a+b+c == 24]
Run Code Online (Sandbox Code Playgroud)
我的失败尝试如下:
[(i,j,k) for i in range(1,11) for j in range(1,i+1) for k in range(1,j+1) if i**2 + j**2 == k**2 i + j + k == 24]
Run Code Online (Sandbox Code Playgroud)
Python 3.4.4
在下面的代码中:
#include <stdio.h>
int main(void) {
char* message = "Hello C Programmer!";
printf("%s", message);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我不完全理解为什么没有必要'*'在printf通话中添加to消息。我是在假设条件下message,因为它是一个指针char,双引号字符串中的第一个字母,将显示该地址的'H'。