我想比较这两个函数的变量
值。不幸的是,我试图使变量
全局
,但我一直得到未定义
。
'use strict';
/**
* @ngdoc function
* @name dashyAppApp.controller:Dashy3Ctrl
* @description
* # Dashy3Ctrl
* Controller of the dashyAppApp
*/
angular.module('dashyAppApp')
.controller('Dashy3Ctrl', function ($rootScope, $scope, employees, $interval) {
var _this = this;
$scope.getData = function() { // getDATA function
employees.getEmployees().then(function(response){
_this.items = response.data;
$scope.items = _this.items;
callmecrazy(response.data);
});
}// End getDATA function
$scope.getData();
$scope.getDataB = function() {
employees.getEmployees().then(function(response){
_this.items = response.data;
callmecrazier(response.data);
});
}
$interval(function(){
$scope.getDataB();
}, 10000);
function callmecrazier(response1){
callmecrazierVal = response1.countries;
return callmecrazierVal;
}
function callmecrazy(response){
callmecrazyVal = response.countries;
return callmecrazyVal;
}
if(!angular.equals(callmecrazierVal(), callmecrazyVal())) {
//trigger some other function
}
});
我想检查如果call mecrazierVal!==calmecrazyVal
。这就是我上面完整的控制器
代码。
if(callmecrazierVal !== callmecrazyVal){
//trigger some other function
}
function callmecrazier(response1){
var callmecrazierVal = response1.countries;
return callmecrazierVal;
}
function callmecrazy(response){
var callmecrazyVal = response.countries;
return callmecrazyVal;
}
if(callmecrazier(response1) !== callmecrazy(response)){
//Your code...........
}
如果函数返回的值不是基元,则应:
if(!angular.equals(callmecrazier(), callmecrazy()) {
//trigger some other function
}
编辑我假设你想在10秒的间隔打api并检查是否有任何变化,对吗?(否则,请澄清你试图实现的目标)。如果是这样,你需要链异步调用,然后比较如下:
'use strict';
/**
* @ngdoc function
* @name dashyAppApp.controller:Dashy3Ctrl
* @description
* # Dashy3Ctrl
* Controller of the dashyAppApp
*/
angular.module('dashyAppApp')
.controller('Dashy3Ctrl', function($rootScope, $scope, employees, $interval) {
var _this = this;
$scope.getData = function() { // getDATA function
return employees.getEmployees().then(function(response) {
return response.data;
});
} // End getDATA function
$scope.getData()
.then(function(data1){
$scope.items = data1;
$interval(function() {
$scope.getData()
.then(function(data2){
if (!angular.equals($scope.items, data1) {
//trigger some other function
}
});
}, 10000);
});
});
你应该从你的函数中返回一些东西。返回的值将与它们进行比较。
function callmecrazier(response1){
var callmecrazierVal = response1.countries;
return callmecrazierVal;
}
function callmecrazy(response){
var callmecrazyVal = response.countries;
return callmecrazyVal;
}
然后像这样比较它们:
if(callmecrazierVal() !== callmecrazyVal()){
//trigger some other function
}
我试图建立一个函数,检查一个单词或文本是否是回文。要做到这一点,它拆分文本,使每个字母都是一个新数组的元素,它去掉空白,并建立反向数组。然后检查两个数组中处于相同位置的每个元素是否相等。如果不是,则返回false,如果是,则返回true。这里的函数是: 我不知道出了什么问题,但是不管我传递给函数什么单词或文本,函数似乎都在返回一个真值。那有什么不好?
问题内容: 我必须比较两个对象(不是)。比较它们的规范方法是什么? 我可以想到: 该运营商只比较基准,因此这将仅适用于较低的整数值的工作。但是也许自动装箱开始了…? 这看起来像一个昂贵的操作。是否以此方式计算出哈希码? 有点冗长… 编辑: 谢谢您的答复。尽管我现在知道该怎么办,但事实已分布在所有现有答案(甚至是已删除的答案)上,我也不知道该接受哪个答案。因此,我将接受最佳答案,即所有三种比较可能性
'application.screenupdating=True Dim WbA As Workbook Set WbA=thisworkbook 在此输入图像描述
我有两个时间戳,一个是我创建的时间戳,另一个是我创建的时间戳(Laravel)。。。在数据库中,两者都有类型时间戳和默认值0000-00-00:00:00。。。但是 给出字符串。而是object/Carbon。这些时间戳有什么问题? 在使用格式('U')转换为整数后,我必须对两者进行比较。我只能在碳对象上调用此方法。我该怎么做?
有没有一个相当标准的C(Linux)函数,或者一种代码高效但性能良好的方法来比较任意大小的两个整数? 我正在寻找一些参数为int intcmp(const void*a,const void*b,size\t size)的东西,它适用于任何实际大小的整数。(如果架构是big-endian的话(我认为)可以工作。) 我倾向于使用这样的实现(通过高效整数比较函数的改进),但它不是完全通用的,并且有足够
过滤出数组中比较函数不返回 true 的所有值。 类似于difference ,除了接受一个 comparator (比较函数)。 使用 Array.filter() 和 Array.findIndex() 来查找合适的值。 const differenceWith = (arr, val, comp) => arr.filter(a => val.findIndex(b => comp(a, b