Skip to content
This repository was archived by the owner on Dec 12, 2023. It is now read-only.

Commit 6b75769

Browse files
committed
merged master
2 parents a95a285 + 255addf commit 6b75769

30 files changed

+604
-1
lines changed

.editorconfig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# editorconfig.org
4+
5+
root = true
6+
7+
8+
[*]
9+
10+
indent_style = space
11+
indent_size = 2
12+
end_of_line = lf
13+
charset = utf-8
14+
trim_trailing_whitespace = true
15+
insert_final_newline = true
16+
17+
[*.md]
18+
trim_trailing_whitespace = false
19+
20+
[Makefile]
21+
indent_style = tab
22+
indent_size = 4

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.DS_Store
22
.idea
33
/out
4-
/core
4+
/core
5+
node_modules

.jshintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
3+
# Pretty dodgy JS to keep it so small
4+
shortest-fizz-buzz

.jshintrc

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"node": true,
3+
"browser": true,
4+
"jquery": true,
5+
"devel": true,
6+
"nonstandard": true,
7+
"worker": true,
8+
"esnext": true,
9+
"bitwise": false,
10+
"boss": true,
11+
"camelcase": true,
12+
"curly": true,
13+
"eqeqeq": true,
14+
"eqnull": true,
15+
"expr": true,
16+
"forin": true,
17+
"immed": true,
18+
"latedef": true,
19+
"newcap": true,
20+
"noarg": true,
21+
"quotmark": "single",
22+
"regexp": true,
23+
"strict": false,
24+
"undef": true,
25+
"unused": true,
26+
"trailing": true,
27+
"smarttabs": true,
28+
"immed": true,
29+
"globals": {
30+
"it": true,
31+
"describe": true
32+
}
33+
}

byte-string/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Byte String
2+
3+
Convert a number to a string that represents a rounded size in bytes.
4+
5+
## Example
6+
7+
```
8+
f(156833213) // => "149.57 MB"
9+
f(8101) // => "7.91 KB"
10+
f(12331, 3) // => "12.042 KB"
11+
```
12+
13+
## Source
14+
15+
By [Riga](https://github.com/riga).

byte-string/byte-string.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = function (bytes, precision) {
2+
var suffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
3+
factor = Math.pow(10, precision > 0 ? precision : 2);
4+
// Using a for loop since it's perfect for this kind of problem
5+
for (var i = bytes, k = 0; i >= 1024 && k < suffixes.length; i /= 1024, k++) {}
6+
// Return the number rounded to precision
7+
return (Math.round(i * factor) / factor) + ' ' + suffixes[k];
8+
};

debounce/Readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Debounce
2+
3+
Write a function that accepts a function and timeout, `x`, in number of milliseconds. It will return a new function that can only be executed on per timeout period - and if the function is invoked during the timeout period, the timeout period restarts. This is useful for functions that can be need to be blocked on subsequent attempts over short period of times. Once such is example, is clicks on a button.
4+
5+
Once written, add a third parameter that will allow the function to be executed immediately if set to true. Otherwise the function will run at the end of the timeout period.

debounce/debounce.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = function (fn, delay, execAsap) {
2+
var timeout; // Keep a reference to the timeout outside the function
3+
4+
return function () {
5+
// Keep the functions execution context and arguments in tact
6+
var that = this,
7+
args = arguments;
8+
9+
// If we already have a function ready to execute, clear it
10+
// Else if we are allowed to execute immediately, call the function
11+
if (timeout) {
12+
clearTimeout(timeout);
13+
} else if (execAsap) {
14+
fn.apply(that, args);
15+
}
16+
17+
timeout = setTimeout(function () {
18+
execAsap || fn.apply(that, args);
19+
timeout = null;
20+
}, delay || 100);
21+
};
22+
};

factorial/factorial.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Recursive function example
2+
exports.recursive = function factorial (number) {
3+
if (number < 2) { return 1; }
4+
5+
return number * factorial(number - 1);
6+
};
7+
8+
// Iterative solution
9+
exports.iterative = function (number) {
10+
var result = 1;
11+
12+
for (var i = 1; i <= number; i++) {
13+
result *= i;
14+
}
15+
16+
return result;
17+
};
18+
19+
// Iterative using a reverse loop
20+
exports.iterativeReverse = function (number) {
21+
var result = 1;
22+
23+
while (number) {
24+
result *= number;
25+
number -= 1;
26+
}
27+
28+
return result;
29+
};

factorial/factorial.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
// Iterative solution
4+
function factorial($number){
5+
$result = 1;
6+
for($i=1; $i <= $number ; $i++){
7+
$result *=$i;
8+
}
9+
return $result;
10+
}
11+
12+
// Iterative using a reverse loop
13+
function factorialReverse($number){
14+
$result = 1;
15+
while($number !=1){
16+
$result *= $number;
17+
$number--;
18+
}
19+
return $result;
20+
}
21+
22+
// Recursive solution
23+
function factorialRecursive($number){
24+
if($number ==1){
25+
return 1;
26+
}
27+
else{
28+
return $number *factorialRecursive($number-1);
29+
}
30+
}
31+
32+
?>

0 commit comments

Comments
 (0)