我有以下内容:
elem :: Eq a => a -> [a] -> Bool
elem _ [] = False
elem x (y:ys) = x == y || elem x ys
Run Code Online (Sandbox Code Playgroud)
我怎样才能证明所有x的y和z都是......
elem z (xs ++ ys) == elem z xs || elem z ys
Run Code Online (Sandbox Code Playgroud)
我试图让左侧等同于右侧,但我的尝试都没有取得丰硕成果.
L.S elem z (x:xs ++ y:ys) = z==x || z==y || elem xs || elem ys
R.S elem z (x:xs) || elem z (y:ys) = z==x || z==y || elem xs || elem ys
Run Code Online (Sandbox Code Playgroud)
有人可以帮我吗?
我不确定我是否走在正确的轨道上,但这就是我所拥有的......
router.post('/login', function(request, response) {
User.find({ 'username': request.body.email,'email':request.body.pwd }, function(err, user) {
//do not know what to add here
Run Code Online (Sandbox Code Playgroud)
我POST从两个输入字段中获取数据,然后使用find命令检查我的mongo数据库中是否已存在此字段.
User是我创建的模型架构.它看起来如此......
var Schema = new mongoose.Schema({
email : String,
password : String,
display : String
});
var User = mongoose.model('User', Schema);
Run Code Online (Sandbox Code Playgroud)
我想我在正确的轨道上,但我不确定在find命令中添加什么.如果两个字段一起存在,我想做一件事,如果不是我想抛出错误,我该怎么做?
假设我有一个如图所示的 css 文件...
span {
//whatever
}
.block {
//whatever
}
.block, .something {
//whatever
}
.more,
h1,
h2 {
//whatever
}
Run Code Online (Sandbox Code Playgroud)
我想提取所有类名并将其放入一个数组中,但我想保留结构,因此该数组看起来像...
["span", ".block", ".block, .something", ".more, h1, h2"]
Run Code Online (Sandbox Code Playgroud)
所以有四个项目。
这是我的尝试...
$homepage = file_get_contents("style.css");
//remove everything between brackets (this works)
$pattern_one = '/(?<=\{)(.*?)(?=\})/s';
//this regex does not work properly
$pattern_two = "/\.([\w]*)\s*{/";
$stripped = preg_replace($pattern_one, '', $homepage);
$selectors = array();
$matches = preg_match_all($pattern_two, $stripped, $selectors);
Run Code Online (Sandbox Code Playgroud)
用于模式 2 的正确正则表达式是什么?
我觉得这可能已经得到了答案,但我找不到类似的问题.一些更有经验的程序员告诉我,以下是不正确的语法:
<input type=...> Name </input>
Run Code Online (Sandbox Code Playgroud)
并且以下是正确的语法:
<input type=..../>
Run Code Online (Sandbox Code Playgroud)
我从来不知道这一点,我总是使用第一个片段,从未遇到任何我所知道的问题.有人可以解释为什么第一个是不正确的,为什么它仍然有效?它是由浏览器获救,还是只是一个样式问题?关于上述语法的任何解释都是可以接受的,因为下次我被要求编写html代码时,我不想冒险看起来像菜鸟.
我想删除文件中包含一种模式但不包含另一种模式的所有行。
例如,如果我有这个文件:
hello people foo
hello world bar
hello something
blah blah blah
Run Code Online (Sandbox Code Playgroud)
我想删除所有包含hello,但不包含 的行world,以便我的文件如下所示:
hello world bar
blah blah blah
Run Code Online (Sandbox Code Playgroud)
我尝试了以下方法:
sed -n '/hello/p' file | sed -i '/world/!d'
Run Code Online (Sandbox Code Playgroud)
但我收到错误消息 -i may not be used with stdin
我试图找到列表中所有内容的平方和,例如:
[1,2,3] --> 1+4+9 --> 14
Run Code Online (Sandbox Code Playgroud)
这是我的尝试:
sqSum :: (a->a)->[a]->a
sqSum _ [] = 0
sqSum f (x:xs) = f x + sqSum f xs
square :: Int->Int
square num = num*num
Run Code Online (Sandbox Code Playgroud)
我这样用它......
sqSum square [1,2,3]
Run Code Online (Sandbox Code Playgroud)
但是我收到一个错误:
square.hs:2:14:
No instance for (Num a) arising from the literal `0'
Possible fix:
add (Num a) to the context of
the type signature for sqSum :: (a -> a) -> [a] -> a
In the expression: 0
In an equation for `sqSum': sqSum …Run Code Online (Sandbox Code Playgroud) 这是我对我的body标签中的div的css :
.background {
top: 0;
left: 0;
right: 0;
z-index: 1;
position: absolute;
display: block;
background: url('Queens-University.jpg');
background-repeat: no-repeat;
background-size: 100px 150px;
width: 100%;
height: 100%;
-webkit-filter: blur(3px);
-moz-filter: blur(2px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
filter: blur(3px);
}
Run Code Online (Sandbox Code Playgroud)
我试图以连续的方式(无限)将这个div的背景图像从左向右移动.
我试图使用jQuery这样做但没有发生任何事情,这是我的代码:
$(window).load(function() {
var image = $('.background');
var x=0;
setInterval(function(){
image.css('background-position', x + 'px 0');
x++;
}, 10);
});
Run Code Online (Sandbox Code Playgroud)
如何使用jQuery移动背景图像?我的功能出了什么问题?
奇怪的是,我找不到关于str汇编语言如何运作的解释.
我明白以下......
str r1,[r2]
Run Code Online (Sandbox Code Playgroud)
...将r1寄存器2的地址中存储寄存器1中的任何内容r2.但是,我想解释str方括号更复杂时的工作原理.例如:
str r1,[r0,r3,lsl#2]
Run Code Online (Sandbox Code Playgroud)
这里发生了什么?我想知道r1最终价值的来源,以及它的价值.我无法测试它,所以我将猜测我认为发生了什么.
r3逻辑上移位2.然后将其添加到r0.最后,r1添加到r0.
这是我的猜测,虽然对我来说这听起来不正确.有人可以为我澄清一下吗?
我有以下代码来检查用户是否存在于数据库中...
router.post('/', function (req, res) {
User.findOne({
username: req.body.log_username,
password: req.body.log_password
}, function (err, docs) {
if (docs.length !== 0) {
console.log("user exists");
}
else {
console.log("no exist");
}
});
});
Run Code Online (Sandbox Code Playgroud)
我有一个主页,如果登录成功,我想将用户发送到该主页。我应该在if语句中放入什么以将使用发送到另一个页面,在这种情况下是home.js. home.js里面有以下代码...
var express = require('express');
var router = express.Router();
router.get('/', function (req, res) {
res.render('home', { title: 'Express' });
});
module.exports = router;
Run Code Online (Sandbox Code Playgroud) 我正在查询文本字段,并希望使用Postgres提取文本中任何位置包含换行符的行。
例如,我想返回如下所示的文本:
row1 -> hello \nthere
row2 -> see you tomorrow\n
Run Code Online (Sandbox Code Playgroud)
我尝试使用类似以下内容:
select descr from description_tb where descr like '%\n%'
然而,这不起作用,因为 \n 可能需要转义,但我不知道如何针对我的情况执行此操作。