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
function chunk(arr, size) { | |
var len = arr.length; | |
var narr = []; | |
for(var i = 0; i < len; i+= size){ | |
narr.push(arr.slice(i, i+size)); | |
} | |
return narr; | |
} | |
chunk(["a", "b", "c", "d"], 2); |
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
function mutation(arr) { | |
var chars = arr[1].toLowerCase().split(''); | |
var str = arr[0].toLowerCase(); | |
for(var i = 0; i < chars.length; i++) { | |
if(str.indexOf(chars[i])<0) { | |
return false; | |
} | |
} | |
return true; | |
} |
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
function bouncer(arr) { | |
return arr.filter(function(v){ return v; }); | |
} | |
bouncer([7, "ate", "", false, 9]); |
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
http://www.freecodecamp.com/challenges/bonfire-seek-and-destroy | |
Incomplete | |
```javasript | |
function destroyer(arr) { | |
var count = function(arr, num){ | |
var i = 0, c = 0; | |
for(i = 0; i < arr.length; i++) { |
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
function where(arr, num) { | |
var i = 0; | |
arr.sort(function(a,b){ return a-b;}); | |
for(i = 0, len = arr.length; i < len && arr[i] < num; i++){ } | |
return i; | |
} | |
where([40, 60], 50); |
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
range() will take care of size of small first, big first problem. | |
You can call range with apply and pass an array into it with receiver set to null. | |
function range(a, b){ | |
var arr = []; | |
if(a > b){ | |
return range(b, a); | |
} | |
for(var i = a; i <= b; i++){ | |
arr.push(i); |
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
A very basic and simple implementation. | |
function range(a, b){ | |
var arr = []; | |
if(a > b){ | |
return range(b, a); | |
} | |
for(var i = a; i <= b; i++){ | |
arr.push(i); | |
} |
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
function diff(arr1, arr2) { | |
var newArr = []; | |
newArr = arr1.filter(function(v){ return arr2.indexOf(v) < 0;}).concat(arr2.filter(function(v){ return arr1.indexOf(v) < 0;})); | |
return newArr; | |
} | |
diff([1, 2, 3, 5], [1, 2, 3, 4, 5]); |
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
function common(arr1, arr2) { | |
var newArr = []; | |
newArr = arr1.filter(function(v){ return arr2.indexOf(v) >= 0;}).concat(arr2.filter(function(v){ return arr1.indexOf(v) >= 0;})); | |
return newArr; | |
} | |
common([1, 2, 3, 5], [1, 2, 3, 4, 5]); |
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
http://www.freecodecamp.com/challenges/bonfire-where-art-thou | |
function where(collection, source) { | |
var arr = []; | |
function matchKeys(curr) { | |
var keys = Object.keys(source); | |
var matched = true; | |
for(var i = 0; i < keys.length; i++){ | |
if(curr[keys[i]] !== source[keys[i]]){ | |
matched = false; |