Skip to content

Commit

Permalink
Solve garageScript#56, Lesson 2: write a function that takes in an ob…
Browse files Browse the repository at this point in the history
…ject (data), a function that takes in key/value, and returns a filtered object
  • Loading branch information
Alberto Lopez committed Oct 27, 2017
1 parent 5fac33d commit e3f9d1e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
19 changes: 0 additions & 19 deletions solutions/filteredObject.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
/*
const objA = {
'5':"blah blah",
'name': "ho",
'zolo': "4thech"
}
const funct = (k, v, objectC={}, i=0)=>{
if(i === k.length){
return objectC;
}
if(v[i].length > 3){
objectC[k[i]]=v[i];
}
return funct(k, v, objectC, i+1);
}
*/

const filterObj = (obj, func)=>{
return func(Object.keys(obj), Object.values(obj));
}
//console.log(filterObj(objA,funct));
module.exports = filterObj;
11 changes: 6 additions & 5 deletions test/filteredObject.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const solution = require('../solutions/filteredObject.js');

const objA = { '5':"blah blah",
'name': "ho", 'zolo': "4thech" }
const objA = { '5':"blah blah",
'name': "ho", 'zolo': "4thech"
}

const funct = (k, v, objectC={}, i=0)=>{
if(i === k.length){
return objectC; } if(v[i].length > 3){ objectC[k[i]]=v[i]; }
return objectC; } if(v[i].length > 3){ objectC[k[i]]=v[i]; }
return funct(k, v, objectC, i+1);
}

Expand All @@ -14,9 +15,9 @@ const test = (object, functions, result, i=0)=>{
return;
}
if(Object.values(solution(object,functions))[i].length == Object.values(result)[i].length){
console.log('equal, and above 3 characters');
console.log('equal objects, and above 3 characters');
}else{
console.log('not equal, and below 3 characters');
console.log('not equal objects, and below 3 characters');
}
return test(object, functions, result, i+1);

Expand Down

0 comments on commit e3f9d1e

Please sign in to comment.