Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some solution updates to arrays and best practices section #214

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 12 additions & 3 deletions app/arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@ exports = typeof window === 'undefined' ? global : window;

exports.arraysAnswers = {
indexOf: function(arr, item) {

return arr.indexOf(item);
},

sum: function(arr) {

var total = 0;
for(var i=0; arr.length > i; i++) {
total += arr[i];
}
return total;
},

remove: function(arr, item) {

var index = arr.indexOf(item);
while(index >=0) {
arr.splice(index,1);
index = arr.indexOf(item);
}
return arr;
},

removeWithoutCopy: function(arr, item) {
Expand Down
5 changes: 3 additions & 2 deletions app/bestPractices.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ exports = typeof window === 'undefined' ? global : window;

exports.bestPracticesAnswers = {
globals: function() {
var myObject;
myObject = {
name: 'Jory'
};
Expand All @@ -17,10 +18,10 @@ exports.bestPracticesAnswers = {
},

parseInt: function(num) {
return parseInt(num);
return parseInt(num, 10);
},

identity: function(val1, val2) {

return val1 === val2;
}
};
15 changes: 14 additions & 1 deletion app/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@ exports = typeof window === 'undefined' ? global : window;

exports.stringsAnswers = {
reduceString: function(str, amount) {

var count = 0;
var result = '';
for(var i = 0; i < str.length; i++) {
if (str[i] === str[i+1]) {
count++
if(count < amount) {
result += str[i];
}
} else {
count = 0;
result += str[i];
}
};
return result;
},

wordWrap: function(str, cols) {
Expand Down
Loading