Skip to content
This repository was archived by the owner on Dec 12, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion balanced-brackets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ process.stdin.on('data', function (chunk) {
// Trim the chunk input
chunk = chunk.trim();
// Process every character on input
for (var i = 0; i < chunk.length; i++) {
for (var i = 0, l = chunk.length; i < l; i++) {
if (brackets[stack[stack.length - 1]] === chunk[i]) {
stack.pop();
} else {
Expand Down
2 changes: 1 addition & 1 deletion bubble-sort/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var bubbleSort = function (array) {
throw new Error('Give me an array');
}

for (var i = 0; i < array.length; i++) {
for (var i = 0, l = array.length; i < l; i++) {
if (array[i] > array[i + 1]) {
switchArray(array, i, i + 1);
var length = i;
Expand Down
4 changes: 2 additions & 2 deletions first-non-repeated-character/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ var firstNonRepeatedCharacter = function (string) {
// Return false to say it's not been repeated
return false;
};
})();
}());

// Interate one extra time past the last character
for (var i = 0; i <= string.length; i++) {
for (var i = 0, l = string.length; i <= l; i++) {
if (checkChar(string[i])) { return prevCharacter; }
}
};
2 changes: 1 addition & 1 deletion flatten-array/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var flatten = function (input) {
var output = [];

for (var i = 0; i < input.length; i++) {
for (var i = 0, l = input.length; i < l; i++) {
// Using Array.isArray for new browsers, in older browsers this can be
// polyfilled using `Object.prototype.toString.call(input[i]) === '[object Array]'`
if (Array.isArray(input[i])) {
Expand Down
4 changes: 2 additions & 2 deletions get-elements-by-class-name/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var getElementsByClassName = function (className) {
var currentNode, currentClass;

// Loop through all the child nodes
for (var i = 0; i < node.childNodes.length; i++) {
for (var i = 0, l = node.childNodes.length; i < l; i++) {
currentNode = node.childNodes[i];
currentClass = currentNode.className;
// Check if the class name exists within the current nodes class
Expand All @@ -31,7 +31,7 @@ var getElementsByClassName = function (className) {

// Loop through all the elements checking the class names against the
// regular expression - when it suceeds just push it into the output array
for (var i = 0; i < elements.length; i++) {
for (var i = 0, l = elements.length; i < l; i++) {
if (regex.test(elements[i].className)) {
found.push(elements[i]);
}
Expand Down
2 changes: 1 addition & 1 deletion longest-palindrome/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var getLongestPalindrome = function (str) {
palindromes.push(result);
};

for (var i = 0; i < str.length; i++) {
for (var i = 0, l = str.length; i < l; i++) {
if (str[i] === str[i - 1]) {
walkPalindrome(str[i] + str[i - 1], str, i - 1, i);
} else if (str[i] === str[i + 1]) {
Expand Down
2 changes: 1 addition & 1 deletion nth-fibonacci/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ For example, the first five Fibonacci numbers are:
0 1 1 2 3
```

If n were 4, your function should return 2; for 5, it should return 3.
If n were 4, your function should return 3; for 5, it should return 5.

Write a function that accepts a number, n, and returns the nth Fibonacci number. Use a recursive solution to this problem; if you finish with time left over, implement an iterative solution.
3 changes: 3 additions & 0 deletions nth-fibonacci/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var fib = function(n) {
return (n === 0 || n === 1) ? n : fib(n - 1) + fib(n - 2);
};
2 changes: 1 addition & 1 deletion subset-of-array/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var isSubsetOf = function (parent, child) {
return checkChild(a, child[childIndex], true);
};

for (var i = 0; i < parent.length; i++) {
for (var i = 0, l = parent.length; i < l; i++) {
if (checkChild(parent[i], child[childIndex])) { return true; }
}

Expand Down
2 changes: 1 addition & 1 deletion sum-of-array-plus-one/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var plus_one_sum = function (array) {
var plus_one_sum = function (array) {
var result = 0;

for (var i = 0; i < array.length; i++) {
for (var i = 0, l = array.length; i < l; i++) {
result += array[i] + 1;
}

Expand Down