Skip to content

Instantly share code, notes, and snippets.

View san-sekhon's full-sized avatar

Sandeep Singh Sekhon san-sekhon

View GitHub Profile

Introduction to Higher-Order Functions

Lessons

Slides 1

Slides 2

Two Forms of Functions

@san-sekhon
san-sekhon / nativeJavaScript.js
Created July 14, 2017 01:32 — forked from alexhawkins/nativeJavaScript.js
Implementation of Native JavaScript Methods (forEach, Map, Filter, Reduce, Every, Some)
'use strict';
/*****************NATIVE forEACH*********************/
Array.prototype.myEach = function(callback) {
for (var i = 0; i < this.length; i++)
callback(this[i], i, this);
};
//tests

Module 2 Assessment

Sales Team

You are managing a sales team and you are interested is analyzing some data related to their age and total sales. Take a moment to review the following data structure you will be analyzing:

var salesTeam = [{name: {first: 'Aleen', last: 'Atkins'}, age: 26, sales: '$2314'},
 		{name: {first: 'Alvaro', last: 'Angelos'}, age: 55, sales: '$1668'},
 		{name: {first: 'Denese', last: 'Dossett'}, age: 29, sales: '$9248'},
// Super basic assertion
// console.log(square(2) === 4);
// Now, let's try writing an assertion that gives us a little more information about what's going on.
/* Write a function, assertEqual, that takes in 3 arguments:
- An invocation of the function you're testing
- The expected output of the function you're testing
/*
Last time
* Conditionals (rps mini game)
This time
* Functions
* Iteration (for and while loop)

Set D

Prompt

//1. Write a function that takes in a number, and returns a string with that many number of stars ("*").

After prompt number 1, you are given this :

function assert(expectedBehavior, descriptionOfCorrectBehavior) {
  if (!expectedBehavior) {
    console.log(descriptionOfCorrectBehavior);

Set C

Prompt

//1. Write a function that checks if the given input is an object.

After prompt number 1, you are given this :

function assert(expectedBehavior, descriptionOfCorrectBehavior) {
  if (!expectedBehavior) {
    console.log(descriptionOfCorrectBehavior);

Set B:

Prompts

//1. extendObject takes in an object, property, and value as parameters and adds the property and value to the object. If the property already exists, overwrite its current value with the new value. Return the object to the user.

Example:

Set A:

Prompts

//1. collectKeys takes an object and returns an array filled with all of they keys inside of the collection.

Example:

  var obj = {course: 'Reactor Prep', best: true};
 collectKeys(obj) // ['course', 'best'];
var library = {
books: {
orwell: ['1984', 'animal farm'],
hemingway: ['A Farewell to Arms', 'The Old Man and the Sea', 'The Sun Also Rises']
},
plays: {
shakespeare: ['romeo and juliet', 'macbeth']
}
};