我正在尝试编写一个带a String和a的函数,Int并返回该字符串"int"次.那是:
duplicate :: String -> Int -> String
Run Code Online (Sandbox Code Playgroud)
如果我要写duplicate "Hello" 3输出应该是"HelloHelloHello".
我正在尝试使用LinkedIn的API访问大学的LinkedIn页面,以定期收集他们有多少粉丝.这似乎可行,但我似乎无法生成一个访问令牌,而没有一些奇怪的重定向URL,必须带你到GUI登录页面!
我正在使用node.js,特别是这个包:https://www.npmjs.org/package/node-linkedin
我有一个API密钥和秘密,所以我需要的是一个访问令牌然后我将被设置为实际开始使用他们的API路由.
var Linkedin = require('node-linkedin')('KEY', 'SECRET', 'callback');
var linkedin = Linkedin.init('my_access_token'); // need a token to initialise!
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
编辑:到目前为止,这是我的代码:
var Linkedin = require('node-linkedin')('KEY', 'SECRET', './oauth/linkedin/callback');
app.get('/oauth/linkedin', function(req, res) {
// This will ask for permisssions etc and redirect to callback url.
Linkedin.auth.authorize(res, ['r_basicprofile', 'r_fullprofile', 'r_emailaddress', 'r_network', 'r_contactinfo', 'rw_nus', 'rw_groups', 'w_messages']);
});
app.get('/oauth/linkedin/callback', function(req, res) {
Linkedin.auth.getAccessToken(res, req.query.code, function(err, results) {
if ( err )
return console.error(err);
/**
* Results have something like:
* {"expires_in":5184000,"access_token":". . …Run Code Online (Sandbox Code Playgroud) 正整数n的整数平方根是最大整数,其平方小于或等于n.(例如,7的整数平方根是2,而9的整数平方根是3).
这是我的尝试:
intSquareRoot :: Int -> Int
intSquareRoot n
| n*n > n = intSquareRoot (n - 1)
| n*n <= n = n
Run Code Online (Sandbox Code Playgroud)
我猜它不起作用,因为n随着递归的增加而减少,但是由于这是Haskell,你不能使用变量来保持原始的n.
我很难向你展示我的代码,因为它遍布整个地方,但我想要做的是:
我在一个函数购买中将html代码注入到DOM中.innerHTML,我希望将一个click事件添加到正在这一步中注入的图标,就像此时我知道它的id.所以在我注射之后我写道:
document.getElementById(product.id+"x").addEventListener("click", removeItem);
product.id 在上面创建,此元素是一个"X"按钮,单击该按钮将从屏幕中删除.
麻烦的是,这个代码运行很多次,因为屏幕上有很多项目需要显示.完成后,按下"X"按钮时,只有最后一次发射.
有什么建议?
编辑:
我无法在这个项目中使用jquery.
这是我的代码:
function createHTML(targetID, product) {
var target = document.getElementById(targetID);
total = (parseFloat(total) + parseFloat(product.price)).toFixed(2);;
target.innerHTML += '<article class="item" id="'+product.id+'"><img class="item_img" src="../'+product.image+'" width=100 height=100><h1 class="item_name">'+product.name+'</h1><p class="item_description">'+product.desc+'</p><h1 class="item_quantity">Quantity: '+product.quantity+'</h1><h1 class="item_price">£'+product.price+'</h1><i id="'+product.id+'x" class="fa fa-times"></i></article>';
document.getElementById(product.id+"x").addEventListener("click", removeItem, true);
}
Run Code Online (Sandbox Code Playgroud) 我在JButton上设置ActionListener时遇到了一些麻烦,这里是代码......
package pipes;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class PipesUI extends javax.swing.JFrame {
Main main = new Main();
JButton addPipeButton = new JButton("Add Pipe");
public PipesUI(){
addUI();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void addUI(){
addPipeButton.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if (e.getSource()==addPipeButton)
main.addPipe();
else
;
}
public static void main(String args[]) {
PipesUI pipesUI = new PipesUI(); // create an instance of the menu
pipesUI.setSize(500,500);
pipesUI.setVisible(true);
}
}
Run Code Online (Sandbox Code Playgroud)
错误发生在addPipeButton.addActionListener(this)行;
(这)它似乎不喜欢,错误说'不兼容的类型:PipesUI无法转换为ActionListener'
任何帮助都会非常感谢.
我正在尝试编写一个从用户读取整数n的程序,然后读取n个整数(在单独的行上),最后显示读取的n个数字的总和.
到目前为止,这是我的代码:
addNumbers :: IO ()
addNumbers = do
putStrLn "Enter a number:"
num <- getInt
addNumbers2 num
addNumbers2 :: Int -> IO ()
addNumbers2 num = do
putStrLn "Enter a number:"
n <- getInt
if num == 1 then
print n
else do
print (n + addNumbers2 (num - 1))
Run Code Online (Sandbox Code Playgroud)
目前它没有编译,错误说:
Couldn't match expected type `Int' with actual type `IO ()'
In the return type of a call of `addNumbers2'
In the second argument of `(+)', namely `addNumbers2 (num …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个countElems带Inta [Int]和a的函数,并返回Int列表中特定数量的函数.到目前为止,我有:
countElems :: Int -> [Int] -> Int
countElems n (x:xs)
| xs == [] = 0
| n == x = 1 + countElems n xs
| n /= x = countElems n xs
Run Code Online (Sandbox Code Playgroud)
运行时,这似乎有效,但在进一步检查时,如果输入的countElems 9 [5, 3, 9, 3, 9]是输出1而不是2.我可以看到这是因为它在检查xs == []之前检查是否n == x导致输出不正确,但如果我交换这两种情况就是说Non-exhaustive pattern.
进一步思考后编辑:
我可以消除使用此代码发布的错误@ user2407038:
countElems :: Int -> [Int] -> Int
countElems _ [] …Run Code Online (Sandbox Code Playgroud)