boolean

Returning true if JavaScript array contains an element

北城余情 提交于 2020-05-09 15:59:17
问题 So far I have this code: var isMatch = viewedUserLikedUsersArray.indexOf(logged_in_user); if (isMatch >=0){ console.log('is match'); } else { console.log('no match'); } If an element is in an array it will return a number greater or equal to 0 and so I can say isMatch >=0 but this doesn't seem the safest way. How else can I return a true/false from the desired code? 回答1: You could just use Array.prototype.some var isMatch = viewedUserLikedUsersArray.some(function(user){ return user === logged

What is the minimum size of a boolean?

有些话、适合烂在心里 提交于 2020-04-30 06:20:13
问题 I was studying about arithmetic types in C++ Prime by Stanley B. Lippman. When the author talks about integral types and the size of each one of them, like for example char is 8 bits, I noticed that it is not so clear the minimum size of a boolean. Considering type conversions, and the following code: bool b = 42; // b is true int i = b; // i had value 1 Can I say that booleans have the same minimum size of an integer (usually 16 bits), since if it is false it would be 0, that is an int, and

Having trouble with some bool/string issues

纵然是瞬间 提交于 2020-04-19 18:04:12
问题 I've got some code-behind that opens like this: namespace MyNamespace { public partial class _Default : Page { public DropDownList DDL_Reporting_RunForDaily; public bool _retrievedData = false; I want to use _retrieveData in a session variable, so I'm setting it to false from the start. Now, I have a "protected void" where I want to change the value of this variable, so I'm using the line: Session["_retrievedData"] = true; Lastly, in another "public void" I want to check the value of the

Having trouble with some bool/string issues

爷,独闯天下 提交于 2020-04-19 18:02:23
问题 I've got some code-behind that opens like this: namespace MyNamespace { public partial class _Default : Page { public DropDownList DDL_Reporting_RunForDaily; public bool _retrievedData = false; I want to use _retrieveData in a session variable, so I'm setting it to false from the start. Now, I have a "protected void" where I want to change the value of this variable, so I'm using the line: Session["_retrievedData"] = true; Lastly, in another "public void" I want to check the value of the

Using Google Sheets scripts, why does my if statement always return false when comparing cell values?

瘦欲@ 提交于 2020-04-11 05:44:27
问题 I need to compare two cell values and act on them if they are different. My "if" statement always returns false when comparing the cell contents however, and I can't figure out why: function onEdit() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheetByName('Sheet1'); // apply to sheet name only var testvalues = sheet.getRange('A1:A2').getValues(); // array of values to be tested var testvalue1 = testvalues[0]; // The contents from A1 var testvalue2 = testvalues[1]; //

Converting Between std::bitset and std::vector<bool>

前提是你 提交于 2020-04-09 19:22:30
问题 I have a std::bitset but now I want to use an STL algorithm on it. I could have used std::vector<bool> instead, but I like std::bitset 's constructor and I want std::bitset 's bitwise operations. Do I have to go through a loop and stuff everything in a std::vector<bool> to use STL algorithms, and then copy that back to the std::bitset , or is there a better way? 回答1: If you do not want to write loops using the operator[] of the bitset , then you might try using bitset::to_string() to convert

php boolean help

半腔热情 提交于 2020-03-27 03:58:17
问题 I seem to have a small problem, in the code below $a_trip is always true, even if $trip!= $admin_trip. Any idea why? if($trip == $admin_trip) $a_trip = true; if($a_trip == true) $trip = ("~::##Admin##::~"); 回答1: In PHP, strings and numbers other than zero will evaluate as true. Make sure that $a_trip is false or empty, or use the equality operator that evaluates type: if($a_trip === true) 回答2: PHP's normal equality is very lax, and considers many values to be the same even when types are

Python Lists Append True Boolean

允我心安 提交于 2020-03-06 04:13:07
问题 The following [incomplete] code is designed to take in an n to x number, of length x-n , and return the value of the next pandigital number. The code identifies which number between n and x is missing from the number passed in as an argument to the function, and returns (for the time being, until the function is further developed), two lists, the original number itself with its individual digits as members of a list, and a list, with the numbers n to x as members, with those numbers which are

Python Lists Append True Boolean

和自甴很熟 提交于 2020-03-06 04:12:35
问题 The following [incomplete] code is designed to take in an n to x number, of length x-n , and return the value of the next pandigital number. The code identifies which number between n and x is missing from the number passed in as an argument to the function, and returns (for the time being, until the function is further developed), two lists, the original number itself with its individual digits as members of a list, and a list, with the numbers n to x as members, with those numbers which are

Send a c++ std::vector<bool> via mpi

爷,独闯天下 提交于 2020-03-01 04:32:27
问题 I know that the storage of a std::vector<bool> is not necessarily an array of bools . If I want to send receive int data stored in a std::vector<int> , I would use MPI_Send(vect.data(),num_of_ints,MPI_INT,dest_rk,tag,comm) . How should I use MPI_Send to send a std::vector<bool> ? In particular : Can / should I use vect.data() as the pointer to buffer ? What MPI type should I give ? Somehow, I feel like MPI_CXX_BOOL does not apply (see this question) What number of elements should I give ?