Questions tagged [truthiness]

In dynamically typed language, truthiness is a term used to describe a value that might evaluate to boolean true.

99 questions
0
votes
0 answers

In which languages is a string not always truthy?

Are there any (other) programming languages where string 'false' is not a truthy value? php yes: echo "" | php yes python kind of: >>> print(('false'==True)) False >>> print(bool('false')) True >>> javascript:…
111
  • 1,788
  • 1
  • 23
  • 38
0
votes
1 answer

VueJS - How to check the truthiness of an object of objects for a v-if

I have this appointments object that has three keyed arrays. I'm trying to find a clean JS way to check the truthiness for a v-if when all three block arrays are empty a la: { "block_1": [], "block_2": [], "block_3": [] } I have…
Matt Larsuma
  • 1,456
  • 4
  • 20
  • 52
0
votes
4 answers

Why can we cast bool to str?

We know how bool() acts on various python objects such as str, int, list. This is a question about the reverse. You can cast bool to int as >>> int(True) 1 >>> int(False) 0 which I think kinda makes sense, but with string we get >>>…
joel
  • 6,359
  • 2
  • 30
  • 55
0
votes
2 answers

Callback function with a truthy value in JavaScript

This is my very first post on StackOverflow, and I would be grateful if you could help me clarify, at a conceptual level, what's happening in the following JavaScript function. So, I've been practicing the language for a while, and I'm now diving a…
Bruno Mazza
  • 675
  • 1
  • 10
  • 24
0
votes
2 answers

Assertions and testing emptiness of iterables

Using the built-in assert statement, is there a good, Pythonic way of checking emptiness in an iterable? I have seen: One-liner to check whether an iterator yields at least one element?; Is there any way to check with Python unittest assert if an…
blacksite
  • 12,086
  • 10
  • 64
  • 109
0
votes
1 answer

Python script to count pixel values fails on a less-than/greater-than comparison

I wrote a short script to count the pixel values in an image: import os import sys import cv2 import numpy as np imn = (sys.argv[1]) a = cv2.imread(imn, 0) b = cv2.imread(imn, 1) c = cv2.GaussianBlur(cv2.imread(imn, 0), (7,7), 2) def NC(img): …
Rich
  • 1,103
  • 1
  • 15
  • 36
0
votes
1 answer

Stuck on JavaScript koans "about_truthyness" section

I'm working on Koans by liammclennan and I'm stuck on the "about_truthyness" section with the following code: module("About Truthyness (topics/about_truthyness.js)"); test("truthyness of positive numbers", function() { var oneIsTruthy = 1 ?…
Bartek
  • 1
0
votes
1 answer

Truthiness checker function in JavaScript

I am going through this challenge on FCC and I am literally half way there! Check if the predicate (second argument) is truthy on all elements of a collection (first argument). function truthCheck(collection, pre) { // Is everyone being…
Antonio Pavicevac-Ortiz
  • 7,239
  • 17
  • 68
  • 141
0
votes
2 answers

Groovy null check not working on a property in the list

POJO: class Item{ String prop1 String prop2 } My Data: List items = new ArrayList(new Item(prop1: 'something'), new Item(prop1: 'something')) Then I try: if(items?.prop2){ //I thought prop 2 is present } even though…
0
votes
0 answers

Why would a truthy check on an enum value not work like I expect?

On my membership model, I have the following enum value: enum relative_type: { member: 0, user: 1 } Then elsewhere in some code, when it comes upon a membership model, I have this if-branch if membership.user? member =…
marcamillion
  • 32,933
  • 55
  • 189
  • 380
0
votes
4 answers

In javascript is -1 true or false?

I can't figure out if -1 is true or false in javascript, when I use indexOf. let a = 'abc'.indexOf('abc'); let b = 'def'.indexOf('abc'); console.log(a); // 0 console.log(b); // -1 console.log(!a); // true console.log(!b); //…
roro
  • 193
  • 3
  • 16
0
votes
1 answer

Why call bool() directly?

I've read that when python evaluates a conditional, that something like if x: would be translated to if bool(x):. Why then do I see a lot of code that calls bool() directly? Is this mostly for readability or is there some other advantage?
Jpaji Rajnish
  • 1,491
  • 4
  • 17
  • 35
0
votes
7 answers

Do-while loop not observing truth assignment (C)

My C project is a Windows console app that takes the time signature and BPM from a user's musical project and returns the length of a bar in seconds. I am trying to use a do-while loop to add a "continue/exit?" prompt at the end of each successful…
0
votes
1 answer

Iterate collection for truthy/falsey values

I have some outstanding requirements for a school assignment that should return truthy/falsy values from a collection. Here are the outstanding requirements: 1) Should pass for a collection of all truthy results 2) Should pass for a collection…
user4774635
0
votes
1 answer

How to check "truthyness" of an object, and then delete the falsy ones and edit the object

I need to take this object, check each properties truthyness, and then remove the untruthy ones. var user = { name: 'my name', email: null, pwHash: 'U+Ldlngx2BYQk', birthday: undefined, username: 'myname33', age: 0 } Here is the code I was trying…
Dylan Lott
  • 421
  • 2
  • 7
  • 19