Category: Scala – Data Types

JavaScript implicit coercion of empty arrays

JavaScript implicit coercion of empty arrays example: [] == ![] //toBoolean [1] [] == !true [] == false //loose equality round one [2] //toPrimitive([]) [3] "" == false //loose equality round two //toBoolean("") [4] false === false true explanations: 1) First there is operator precedence so ! evaluates before == Negating something calls the internal toBoolean method onto that "something" first. … Continue reading JavaScript implicit coercion of empty arrays

Advertisements

Sort numbers in ascending order using Python

This is Python code to sort the numbers in ascending order input: 3,0,1,4,2 out:0,1,2,3,4 Example is my: numbers = input("Enter numbers separated by a comma: ") numbers = [int(n) for n in numbers.split(',')] end = len(numbers) - 1 while end != 0: for i in range(end): if numbers[i] > numbers[i + 1]: numbers[i], numbers[i + … Continue reading Sort numbers in ascending order using Python

Prime Number Generator (6n + 1 or 6n – 1)

Prime Number Generator (6n + 1 or 6n - 1) This generator is like most where it brute forces an integer: it see whether the integer is divisible by any of the primes; if so, then it's not a prime and vice versa. This though only compares values 6n + 1 and 6n - 1 starting with n as 1 as … Continue reading Prime Number Generator (6n + 1 or 6n – 1)

Collatz Conjecture Meet of 2 Numbers in python

def first_collatz(n, visited): counter = 0 while n > 1: counter += 1 n = 3 * n + 1 if n & 1 else n >> 1 if n not in visited: visited[n] = counter def secondd_collatz(n, other): counter = 0 if n not in other: while n > 1: counter += 1 n … Continue reading Collatz Conjecture Meet of 2 Numbers in python

Simple budget program in python

I've decided to start working on a budget application for the purposes of enhancing my Python skills. In its current form this program takes given expenses and income and tells the user whether they have a surplus, a deficit, or if they are breaking even. Example: import os import sys class Application(): def __init__(self): self.income … Continue reading Simple budget program in python

Asynchronous programming in Scala with Future

What is Future? A future object is an object whose value will be removed at some point in the future. This value is usually the result of a calculation process. This calculation returns the result value, we say that the Future object has completed that value, and vice versa. If an Exception is returned, the … Continue reading Asynchronous programming in Scala with Future

Array in scala enter form keyboard

This is function scala programer enter N element Interger form keyboard. Example: import scala.io._ object InputArray { def main(args: Array[String]): Unit = { println("Please enter n all element?") val n = StdIn.readInt() println("---------begin--------") val IntArr = Array.fill(n.toInt) { StdIn.readInt() } println("---------result--------") for (x <- IntArr) { println("x:" + x) } } } Reuslt:

Type Parameter is Scala

Class in Scala can receive a special parameter type, called Type Parameter. This type of parameter is not the same as normal variables as other parameters, but a parameter that specifies the type. That's why it's called Type Parameter. While Class is defined, it is entirely possible to manipulate an unknown type (specified when calling … Continue reading Type Parameter is Scala

Scala Data Type – Description

Sr.No Data Type & Description 1 Byte 8 bit signed value. Range from -128 to 127 2 Short 16 bit signed value. Range -32768 to 32767 3 Int 32 bit signed value. Range -2147483648 to 2147483647 4 Long 64 bit signed value. -9223372036854775808 to 9223372036854775807 5 Float 32 bit IEEE 754 single-precision float 6 Double … Continue reading Scala Data Type – Description