This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr = [1, 2, 3, 4, 5]; | |
function sumArray(array){ | |
var sum = array.reduce(function(a, b){ | |
return a + b; | |
}, 0); | |
return sum; | |
} | |
sumArray(arr); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Using pytest tool | |
# $ pip install -U pytest | |
# $ pytest test_class.py -v | |
# https://docs.pytest.org/en/stable/usage.html | |
class TestClass: | |
def test_one(self): | |
x = "this" | |
assert ("h" in x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A; B # Run A and then B, regardless of success of A | |
A && B # Run B if and only if A succeeded | |
A || B # Run B if and only if A failed | |
A & # Run A in background. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://github.com/WebDevSimplified/Noob-Vs-Pro-Code/blob/master/1-logic/3-pro.js | |
/* Rather than checking for null which does not factor that if the value is undefined, you can check for if value is true. | |
* This way the returned value is always either a 0 , or a positive number (or pos. n with parentheses) | |
* Is this a "proper solution" to this problem(?) maybe... | |
*/ | |
function numberToAccountingString(number){ | |
if( !number) return '0' | |
if (number < 0) return `(${Math.abs(number)})` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const isWeekday = (date) => date.getDay() % 6 !== 0; | |
console.log(isWeekday(new Date(2021, 1, 25))); | |
// Result: true (Thurday 25.2.21) | |
console.log(isWeekday(new Date(2021, 1, 28))); | |
// Result: false (Sunday 28.2.21) | |
console.log(isWeekday(new Date()),new Date()) | |
//Todays date |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
int a= 21; | |
int b =0; | |
if (a%4!=0) b++; | |
var c = (a/4)+b; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Linq; | |
public class Program | |
{ | |
public static void Main() | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Adds floats together with "precision" | |
var RoundedAddition = (...args) => { | |
let countDecimals = (value) => { | |
if (Math.floor(value) === value) return 0; | |
let a = value.toString().split(".")[1].length || 0; | |
return a; | |
} | |
let highestDecimalpoint; | |
args.forEach(i => { | |
let x = countDecimals(i); |
OlderNewer