我正在尝试使用swift构建一个函数来映射数组,将数组中的每个值除以3,然后吐出一个新数组.这是我到目前为止:
func divideby3Map<T, U>(y: [T], z: T -> U) -> [U] {
let array = [int]()
let divideby3Array = array.map { [y] / 3 }
return dividedby3Array
}
divideby3Map([1,2,3,4,5])
Run Code Online (Sandbox Code Playgroud)
凡T和U是原始数组,分别返回的新阵列,它的使用泛型来完成.
我确定这不是正确编写的,我坚持正确的语法.例如,由于返回的数组由泛型表示[U],我假设我必须在返回的数组中的某处使用它,但不确定在哪里.
我正在尝试设置用于处理我的javascript函数中的成功和错误的协议,但是当函数成功时它似乎没有合作.我收到以下错误:
Failed with: TypeError: Object #<Object> has no method 'success'
at Object.Parse.Cloud.httpRequest.success (main.js:77:20)
at Object.<anonymous> (<anonymous>:571:19)
Run Code Online (Sandbox Code Playgroud)
这是完整的功能:
// Sends search query to eBay
Parse.Cloud.define("eBayCategorySearch", function(request, response) {
url = 'http://svcs.ebay.com/services/search/FindingService/v1';
Parse.Cloud.httpRequest({
url: url,
params: {
'OPERATION-NAME' : 'findItemsByKeywords',
'SERVICE-VERSION' : '1.12.0',
'SECURITY-APPNAME' : '*App ID GOES HERE*',
'GLOBAL-ID' : 'EBAY-US',
'RESPONSE-DATA-FORMAT' : 'JSON',
'itemFilter(0).name=ListingType' : 'itemFilter(0).value=FixedPrice',
'keywords' : request.params.item,
},
success: function (httpResponse) {
// parses results
var response = JSON.parse(httpResponse.text);
var items = [];
response.findItemsByKeywordsResponse.forEach(function(itemByKeywordsResponse) {
itemByKeywordsResponse.searchResult.forEach(function(result) {
result.item.forEach(function(item) …Run Code Online (Sandbox Code Playgroud)