Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

18 changes: 0 additions & 18 deletions .eslintrc.json

This file was deleted.

2 changes: 0 additions & 2 deletions .gitignore

This file was deleted.

22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# JavaScript I
# JavaScript I Stretch Assignment

## Instructions
* This repository is to be used as a Stretch Assignment for those looking for more reps and deeper understanding of concepts.

## Project initialization

Do not use any of the built in Javascript Array methods like .forEach .map etc. If you'd like feel free to reuse any of your functions along the way though!
* `Fork and Clone` this repository and cd into it.
* complete all of the exercises in each file.
* As you complete an exercise be sure to use invoke your functions and `console.log` to print out the output of your function.
* Once the proper output is demonstrated, commit your code to your fork.

## Instructions

#### Fork and clone this repo.
* Clone this repository and navigate into it.
* Run the command `npm i` to install needed node packages.
* Run the command `npm test` to run the tests.
* Work through the files and make the tests pass.
* Suggested order: `callbacks.js` (no tests), `arrays.js`, `objects.js`, `closure.js`.
* Submit a pull request when you are finished and we will review your code.
* As soon as you've completed all the coding problems, submit a `pull-request` with a copy of your fork and link it over to your Project Manager. Good luck!
* Once everything is complete, refactor your solutions to use `arrow functions` as opposed to the function keyword
54 changes: 54 additions & 0 deletions assignments/arrays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const items = [1, 2, 3, 4, 5, 5]; // use this array to test your code.
/*
Complete the following functions.
These functions only need to work with arrays.
A few of these functions mimic the behavior of the `Built` in JavaScript Array Methods.
The idea here is to recreate the functions from scratch BUT if you'd like,
feel free to Re-use any of your functions you build within your other functions.
**DONT** Use for example. .forEach() to recreate each, and .map() to recreate map etc.
You CAN use concat, push, pop, etc. but do not use the exact method that you are replicating
*/

function each(elements, cb) {
// Do NOT use forEach to complete this function.
// Iterates over a list of elements, yielding each in turn to the `cb` function.
// This only needs to work with arrays.
// You should also pass the index into `cb` as the second argument
// based off http://underscorejs.org/#each
}

function map(elements, cb) {
// Do NOT use .map, to complete this function.
// How map works: Map calls a provided callback function once for each element in an array, in order, and functionructs a new array from the res .
// Produces a new array of values by mapping each value in list through a transformation function (iteratee).
// Return the new array.
}

function reduce(elements, cb, startingValue) {
// Do NOT use .reduce to complete this function.
// How reduce works: A reduce function combines all elements into a single value going from left to right.
// Elements will be passed one by one into `cb` along with the `startingValue`.
// `startingValue` should be the first argument passed to `cb` and the array element should be the second argument.
// `startingValue` is the starting value. If `startingValue` is undefined then make `elements[0]` the initial value.
}

function find(elements, cb) {
// Do NOT use .includes, to complete this function.
// Look through each value in `elements` and pass each element to `cb`.
// If `cb` returns `true` then return that element.
// Return `undefined` if no elements pass the truth test.
}

function filter(elements, cb) {
// Do NOT use .filter, to complete this function.
// Similar to `find` but you will return an array of all elements that passed the truth test
// Return an empty array if no elements pass the truth test
}

const nestedArray = [1, [2], [[3]], [[[4]]]]; // use this to test 'flatten'

function flatten(elements) {
// Flattens a nested array (the nesting can be to any depth).
// Hint: You can solve this using recursion.
// Example: flatten([1, [2], [3, [[4]]]]); => [1, 2, 3, 4];
}
33 changes: 7 additions & 26 deletions src/closure.js → assignments/closure.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,20 @@
// Complete the following functions.

const counter = () => {
// Return a function that when invoked increments and returns a counter variable.
// Example: const newCounter = counter();
// newCounter(); // 1
// newCounter(); // 2
};

const counterFactory = () => {
function counterFactory() {
// Return an object that has two methods called `increment` and `decrement`.
// `increment` should increment a counter variable in closure scope and return it.
// `decrement` should decrement the counter variable and return it.
};
}

const limitFunctionCallCount = (cb, n) => {
function limitFunctionCallCount(cb, n) {
// Should return a function that invokes `cb`.
// The returned function should only allow `cb` to be invoked `n` times.
};

/* STRETCH PROBLEM */
// Returning null is acceptable if cb can't be returned
}

const cacheFunction = (cb) => {
function cacheFunction(cb) {
// Should return a funciton that invokes `cb`.
// A cache (object) should be kept in closure scope.
// The cache should keep track of all arguments have been used to invoke this function.
// If the returned function is invoked with arguments that it has already seen
// then it should return the cached result and not invoke `cb` again.
// `cb` should only ever be invoked once for a given set of arguments.
};

/* eslint-enable no-unused-vars */

module.exports = {
counter,
counterFactory,
cacheFunction,
limitFunctionCallCount,
};
}
39 changes: 15 additions & 24 deletions src/objects.js → assignments/objects.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,40 @@
const testObject = { name: 'Bruce Wayne', age: 36, location: 'Gotham' }; // use this object to test your functions

// Complete the following underscore functions.
// Reference http://underscorejs.org/ for examples.

const keys = (obj) => {
function keys(obj) {
// Retrieve all the names of the object's properties.
// Return the keys as strings in an array.
// Based on http://underscorejs.org/#keys
};
}

const values = (obj) => {
function values(obj) {
// Return all of the values of the object's own properties.
// Ignore functions
// http://underscorejs.org/#values
};
}

const mapObject = (obj, cb) => {
// Like map for arrays, but for objects. Transform the value of each property in turn.
function mapObject(obj, cb) {
// Like map for arrays, but for objects. Transform the value of each property in turn by passing it to the callback function.
// http://underscorejs.org/#mapObject
};
}

const pairs = (obj) => {
function pairs(obj) {
// Convert an object into a list of [key, value] pairs.
// http://underscorejs.org/#pairs
};
}

/* STRETCH PROBLEMS */

const invert = (obj) => {
function invert(obj) {
// Returns a copy of the object where the keys have become the values and the values the keys.
// Assume that all of the object's values will be unique and string serializable.
// http://underscorejs.org/#invert
};
}

const defaults = (obj, defaultProps) => {
function defaults(obj, defaultProps) {
// Fill in undefined properties that match properties on the `defaultProps` parameter object.
// Return `obj`.
// http://underscorejs.org/#defaults
};

/* eslint-enable no-unused-vars */

module.exports = {
keys,
values,
mapObject,
pairs,
invert,
defaults,
};
}
Loading