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
// running the function with `objectA` and `expectedKeys` | |
// should return `true` | |
var objectA = { | |
id: 2, | |
name: 'Jane Doe', | |
age: 34, | |
city: 'Chicago' | |
} | |
// running the function with `objectB` and `expectedKeys` |
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
// you can pass in `scratchData` to test out `findByid` | |
// your function | |
var scratchData = [ | |
{id: 22, foo: 'bar'}, | |
{id: 28, foo: 'bizz'}, | |
{id: 19, foo: 'bazz'} | |
]; | |
function findById(items, idNum) { | |
var myArray=[]; |
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
var studentData = [ | |
{ | |
name: 'Tim', | |
status: 'Current student', | |
course: 'Biology' | |
}, | |
{ | |
name: 'Sue', | |
status: 'Withdrawn', | |
course: 'Mathematics' |
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
var studentData = [ | |
{ | |
name: 'Tim', | |
status: 'Current student', | |
course: 'Biology' | |
}, | |
{ | |
name: 'Sue', | |
status: 'Withdrawn', | |
course: 'Mathematics' |
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 makeStudentsReport(data) { | |
var myArray =[]; | |
for (var i=0; i<data.length; i++){ | |
var paramtr = data[i]; | |
myArray.push(paramtr.name + ': ' + paramtr.grade); | |
} | |
return myArray; | |
} | |
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 getTokens(rawString) { | |
// NB: `.filter(Boolean)` removes any falsy items from an array | |
return rawString.toLowerCase().split(/[ ,!.";:-]+/).filter(Boolean).sort(); | |
} | |
//This function counts the number of times each word appears in the text (colletion) | |
function mostFrequentWord(text) { | |
//the getTokens function is invoked and the results are saved as the variable words | |
var words = getTokens(text); | |
//the wordFrequencies array is created |
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 keyDeleter(obj) { | |
delete obj.foo; | |
delete obj.bar; | |
return obj; | |
} | |
var sampleObj = { | |
foo: 'foo', | |
bar: 'bar', |
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 personMaker() { | |
var person = { | |
firstName: 'Paul', | |
lastName: 'Jones', | |
// replace `null` with a function that uses self reference to return | |
// full name | |
fullName: function(){ | |
return (this.firstName + " " + this.lastName); | |
} | |
}; |
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 updateObject(obj) { | |
obj.foo ='foo'; | |
obj.bar ='bar'; | |
obj.bizz ='bizz'; | |
obj.bang ='bang'; | |
return obj; | |
} |
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 createMyObject() { | |
return { | |
foo:'bar', | |
answerToUniverse:42, | |
'olly olly':'oxen free', | |
sayHello:function(){ | |
return 'hello'; | |
} | |
} | |
} |