This repository has been archived by the owner on Nov 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from rmurphey/refactor
update solutions to match new exports pattern after removing require
- Loading branch information
Showing
13 changed files
with
419 additions
and
477 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,135 +1,133 @@ | ||
if (typeof define !== 'function') { var define = require('amdefine')(module); } | ||
|
||
define(function() { | ||
return { | ||
indexOf : function(arr, item) { | ||
/* | ||
if (Array.prototype.indexOf) { return arr.indexOf(item); } | ||
*/ | ||
|
||
for (var i = 0, len = arr.length; i < len; i++) { | ||
if (arr[i] === item) { | ||
return i; | ||
} | ||
exports = (typeof window === 'undefined') ? global : window; | ||
|
||
exports.arraysAnswers = { | ||
indexOf : function(arr, item) { | ||
/* | ||
if (Array.prototype.indexOf) { return arr.indexOf(item); } | ||
*/ | ||
|
||
for (var i = 0, len = arr.length; i < len; i++) { | ||
if (arr[i] === item) { | ||
return i; | ||
} | ||
} | ||
|
||
return -1; | ||
}, | ||
return -1; | ||
}, | ||
|
||
sum : function(arr) { | ||
var sum = 0; | ||
sum : function(arr) { | ||
var sum = 0; | ||
|
||
for (var i = 0, len = arr.length; i < len; i++) { | ||
sum += arr[i]; | ||
} | ||
for (var i = 0, len = arr.length; i < len; i++) { | ||
sum += arr[i]; | ||
} | ||
|
||
return sum; | ||
}, | ||
return sum; | ||
}, | ||
|
||
remove : function(arr, item) { | ||
var ret = []; | ||
remove : function(arr, item) { | ||
var ret = []; | ||
|
||
for (var i = 0, len = arr.length; i < len; i++) { | ||
if (arr[i] !== item) { | ||
ret.push(arr[i]); | ||
} | ||
for (var i = 0, len = arr.length; i < len; i++) { | ||
if (arr[i] !== item) { | ||
ret.push(arr[i]); | ||
} | ||
} | ||
|
||
return ret; | ||
}, | ||
return ret; | ||
}, | ||
|
||
removeWithoutCopy : function(arr, item) { | ||
var i, len; | ||
removeWithoutCopy : function(arr, item) { | ||
var i, len; | ||
|
||
for (i = 0, len = arr.length; i < len; i++) { | ||
if (arr[i] === item) { | ||
arr.splice(i, 1); | ||
i = i - 1; | ||
len = len - 1; | ||
} | ||
for (i = 0, len = arr.length; i < len; i++) { | ||
if (arr[i] === item) { | ||
arr.splice(i, 1); | ||
i = i - 1; | ||
len = len - 1; | ||
} | ||
} | ||
|
||
return arr; | ||
}, | ||
|
||
append : function(arr, item) { | ||
arr.push(item); | ||
return arr; | ||
}, | ||
|
||
truncate : function(arr) { | ||
arr.pop(); | ||
return arr; | ||
}, | ||
|
||
prepend : function(arr, item) { | ||
arr.unshift(item); | ||
return arr; | ||
}, | ||
|
||
curtail : function(arr) { | ||
arr.shift(arr); | ||
return arr; | ||
}, | ||
|
||
concat : function(arr1, arr2) { | ||
return arr1.concat(arr2); | ||
}, | ||
|
||
insert : function(arr, item, index) { | ||
arr.splice(index, 0, item); | ||
return arr; | ||
}, | ||
|
||
count : function(arr, item) { | ||
var count = 0; | ||
|
||
for (var i = 0, len = arr.length; i < len; i++) { | ||
if (arr[i] === item) { | ||
count++; | ||
} | ||
} | ||
return arr; | ||
}, | ||
|
||
return count; | ||
}, | ||
append : function(arr, item) { | ||
arr.push(item); | ||
return arr; | ||
}, | ||
|
||
duplicates : function(arr) { | ||
var seen = {}; | ||
var dupes = []; | ||
truncate : function(arr) { | ||
arr.pop(); | ||
return arr; | ||
}, | ||
|
||
for (var i = 0, len = arr.length; i < len; i++) { | ||
seen[arr[i]] = seen[arr[i]] ? seen[arr[i]] + 1 : 1; | ||
} | ||
prepend : function(arr, item) { | ||
arr.unshift(item); | ||
return arr; | ||
}, | ||
|
||
for (var item in seen) { | ||
if (seen.hasOwnProperty(item) && seen[item] > 1) { | ||
dupes.push(item); | ||
} | ||
} | ||
curtail : function(arr) { | ||
arr.shift(arr); | ||
return arr; | ||
}, | ||
|
||
concat : function(arr1, arr2) { | ||
return arr1.concat(arr2); | ||
}, | ||
|
||
return dupes; | ||
}, | ||
insert : function(arr, item, index) { | ||
arr.splice(index, 0, item); | ||
return arr; | ||
}, | ||
|
||
square : function(arr) { | ||
var ret = []; | ||
count : function(arr, item) { | ||
var count = 0; | ||
|
||
for (var i = 0, len = arr.length; i < len; i++) { | ||
ret.push(arr[i] * arr[i]); | ||
for (var i = 0, len = arr.length; i < len; i++) { | ||
if (arr[i] === item) { | ||
count++; | ||
} | ||
} | ||
|
||
return ret; | ||
}, | ||
return count; | ||
}, | ||
|
||
findAllOccurrences : function(arr, target) { | ||
var ret = []; | ||
duplicates : function(arr) { | ||
var seen = {}; | ||
var dupes = []; | ||
|
||
for (var i = 0, len = arr.length; i < len; i++) { | ||
if (arr[i] === target) { | ||
ret.push(i); | ||
} | ||
for (var i = 0, len = arr.length; i < len; i++) { | ||
seen[arr[i]] = seen[arr[i]] ? seen[arr[i]] + 1 : 1; | ||
} | ||
|
||
for (var item in seen) { | ||
if (seen.hasOwnProperty(item) && seen[item] > 1) { | ||
dupes.push(item); | ||
} | ||
} | ||
|
||
return ret; | ||
return dupes; | ||
}, | ||
|
||
square : function(arr) { | ||
var ret = []; | ||
|
||
for (var i = 0, len = arr.length; i < len; i++) { | ||
ret.push(arr[i] * arr[i]); | ||
} | ||
}; | ||
}); | ||
|
||
return ret; | ||
}, | ||
|
||
findAllOccurrences : function(arr, target) { | ||
var ret = []; | ||
|
||
for (var i = 0, len = arr.length; i < len; i++) { | ||
if (arr[i] === target) { | ||
ret.push(i); | ||
} | ||
} | ||
|
||
return ret; | ||
} | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,24 @@ | ||
if (typeof define !== 'function') { var define = require('amdefine')(module); } | ||
exports = (typeof window === 'undefined') ? global : window; | ||
|
||
define([ 'jquery' ], function($) { | ||
return { | ||
async : function(value) { | ||
var dfd = $.Deferred(); | ||
setTimeout(function() { | ||
dfd.resolve(value); | ||
}, 10); | ||
return dfd.promise(); | ||
}, | ||
exports.asyncAnswers = { | ||
async : function(value) { | ||
var dfd = $.Deferred(); | ||
setTimeout(function() { | ||
dfd.resolve(value); | ||
}, 10); | ||
return dfd.promise(); | ||
}, | ||
|
||
manipulateRemoteData : function(url) { | ||
var dfd = $.Deferred(); | ||
manipulateRemoteData : function(url) { | ||
var dfd = $.Deferred(); | ||
|
||
$.ajax(url).then(function(resp) { | ||
var people = $.map(resp.people, function(person) { | ||
return person.name; | ||
}); | ||
dfd.resolve(people.sort()); | ||
$.ajax(url).then(function(resp) { | ||
var people = $.map(resp.people, function(person) { | ||
return person.name; | ||
}); | ||
dfd.resolve(people.sort()); | ||
}); | ||
|
||
return dfd.promise(); | ||
} | ||
}; | ||
}); | ||
return dfd.promise(); | ||
} | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,37 @@ | ||
if (typeof define !== 'function') { var define = require('amdefine')(module); } | ||
exports = (typeof window === 'undefined') ? global : window; | ||
|
||
/** | ||
* This file defines an object with some methods. Some of these methods are | ||
* populated incorrectly; your job is to fix them. Other methods are not | ||
* populated at all; your job is to fill them out. | ||
*/ | ||
define(function() { | ||
return { | ||
exports.bestPracticesAnswers = { | ||
|
||
globals : function() { | ||
var myObject = { | ||
name : 'Jory' | ||
}; | ||
globals : function() { | ||
var myObject = { | ||
name : 'Jory' | ||
}; | ||
|
||
return myObject; | ||
}, | ||
return myObject; | ||
}, | ||
|
||
functions : function(flag) { | ||
var getValue; | ||
functions : function(flag) { | ||
var getValue; | ||
|
||
if (flag) { | ||
getValue = function() { return "a"; } | ||
} else { | ||
getValue = function() { return "b"; } | ||
} | ||
if (flag) { | ||
getValue = function() { return "a"; } | ||
} else { | ||
getValue = function() { return "b"; } | ||
} | ||
|
||
return getValue(); | ||
}, | ||
return getValue(); | ||
}, | ||
|
||
parseInt : function(num) { | ||
return parseInt(num, 10); | ||
}, | ||
parseInt : function(num) { | ||
return parseInt(num, 10); | ||
}, | ||
|
||
identity : function(val1, val2) { | ||
return val1 === val2; | ||
} | ||
}; | ||
}); | ||
identity : function(val1, val2) { | ||
return val1 === val2; | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.