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
#!/bin/bash | |
# Try to guess number | |
# Function that generates numbers based on range | |
function random { | |
num=$(($RANDOM%$1+1)) | |
echo $num | |
} | |
function noargs { |
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
/*! | |
* Big Integer Sum Algorithm | |
* | |
* | |
* Result sum( '5' * 10^7, '8' * 10^7) | |
* real 0m2.995s | |
* user 0m2.928s | |
* sys 0m0.060s | |
*/ |
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
// <---------------> Array methods <-------------------> | |
// Array.from(arrayLike or iterable, mapFunc?, thisArg?) | |
Array.from("hello", c => c.toUpperCase()); | |
// Array.of(...items) | |
Array.of(...'hello'); | |
// -- Array prototype methods | |
// Array.prototype.keys() => Returns iterator of keys | |
['a', 'b', 'c'].keys(); // 0.. 1.. 2.. | |
// Array.prototype.values() => Returns iterator of values | |
['a', 'b', 'c'].values(); // 'a'.. 'b'.. 'c'.. |
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
// --- All ways to import a module (main.js) | |
import MyDefault from './m1'; | |
import { square, diag } from './m1' | |
import { square as sq, diag as dg} from './m1' | |
import * as lib from './m1' | |
import { default as foo } from './m1' | |
import Animal from './m1'; | |
import './m1' // loads the module (executes the body) | |
// but doesn't import anything | |
import MyDefault, * as lib from './m1' |
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
// Template strings | |
`Hello my name is ${firstName} ${lastName}` | |
// Mult-line | |
`This is a multi-line | |
string that appears | |
to be very cool perhaps | |
it is.` | |
// Tagged template | |
tagFunction`Hello\n ${firstName} ${lastName}` | |
// Implement tagFunction |
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
// Primitive value | |
typeof Symbol(); // 'symbol' | |
// Unique | |
Symbol() === Symbol(); // false | |
// Invoked without `new` | |
new Symbol(); // TypeError: Symbol is not a constructor | |
// Set description of Symbol | |
let sy = Symbol('personal primitive'); | |
String(sy); // 'Symbol(personal primitive)' | |
// Symbols as property keys and method names |
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
// If strings starts with substr | |
'myString'.startsWith('my', 0 /* start searching */); // true | |
// If string ends with substr | |
'myString'.endsWith('ring', 8 /* end searching */); // true | |
// If strings has another substr | |
'myString'.includes('str', 0 /* start searching */); // true | |
// Multiply string | |
'woof '.repeat(5); | |
// -- Template strings | |
// String interpolation |
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
// Get sign of number (-1, +1) or NaN or (-+)zero | |
Math.sign(-8); // -1 | |
Math.sign(2); // 1 | |
Math.sign(0); // 0 | |
Math.sign(-0); // -0 | |
Math.sign(NaN); // NaN | |
// Remove decimal fraction of x | |
Math.trunc(Math.PI); // 3 | |
Math.trunc(-3.99999); // -3 | |
// Cube root of 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
// Octals 0 + o + integer | |
0o8 | |
// Binary 0 + b + integer | |
0b11 | |
// ParseInt doesn't support binary literals | |
parseInt('0b11', 2); // 0 | |
// Instead use Number() | |
Number('0b11'); // 3 | |
// Or remove prefix | |
parseInt('11', 2); // 3 |
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
<colorful>YOU HAVE WON CLICK FOR PRIZE</colorful> <BR> | |
<colorful>YOU HAVE WON CLICK FOR PRIZE</colorful> <BR> | |
<colorful>YOU HAVE WON CLICK FOR PRIZE</colorful> <BR> | |
<colorful>YOU HAVE WON CLICK FOR PRIZE</colorful> <BR> | |
<colorful>YOU HAVE WON CLICK FOR PRIZE</colorful> <BR> | |
<colorful>YOU HAVE WON CLICK FOR PRIZE</colorful> <BR> |