@jolduca/lotide
Advanced tools
Comparing version 0.1.0 to 0.9.0
@@ -19,2 +19,4 @@ const countLetters = function(string) { | ||
console.log(countLetters('lighthouse in the house')); | ||
module.exports = countLetters; | ||
// console.log(countLetters('lighthouse in the house')); |
@@ -20,26 +20,21 @@ // allItems: an array of strings that we need to look through | ||
const assertEqual = function(actual, expected) { | ||
if (actual === expected) console.log( | ||
`✅✅✅ Assertion Passed: ${actual} === ${expected}`); | ||
else console.log( | ||
`⛑️⛑️⛑️ Assertion Failed: ${actual} !== ${expected}`); | ||
}; | ||
module.exports = countOnly; | ||
const firstNames = [ | ||
"Karl", | ||
"Salima", | ||
"Agouhanna", | ||
"Fang", | ||
"Kavith", | ||
"Jason", | ||
"Salima", | ||
"Fang", | ||
"Joe" | ||
]; | ||
// const firstNames = [ | ||
// "Karl", | ||
// "Salima", | ||
// "Agouhanna", | ||
// "Fang", | ||
// "Kavith", | ||
// "Jason", | ||
// "Salima", | ||
// "Fang", | ||
// "Joe" | ||
// ]; | ||
const result1 = countOnly(firstNames, { "Jason": true, "Karima": true, "Fang": true, "Agouhanna": false }); | ||
// const result1 = countOnly(firstNames, { "Jason": true, "Karima": true, "Fang": true, "Agouhanna": false }); | ||
assertEqual(result1["Jason"], 1); | ||
assertEqual(result1["Karima"], undefined); | ||
assertEqual(result1["Fang"], 2); | ||
assertEqual(result1["Agouhanna"], undefined); | ||
// assertEqual(result1["Jason"], 1); | ||
// assertEqual(result1["Karima"], undefined); | ||
// assertEqual(result1["Fang"], 2); | ||
// assertEqual(result1["Agouhanna"], undefined); |
@@ -1,2 +0,1 @@ | ||
const assertEqual = require('./assertEqual'); | ||
// FUNCTION IMPLEMENTATION | ||
@@ -3,0 +2,0 @@ const eqArrays = function(firstList, secondList) { |
@@ -0,1 +1,3 @@ | ||
const eqArrays = require('./eqArrays'); | ||
const eqObjects = function(firstObj, secondObj) { | ||
@@ -52,40 +54,4 @@ let areEqual = false; | ||
const eqArrays = function(firstList, secondList) { | ||
let areSame = false; | ||
module.exports = eqObjects; | ||
if (areSameLength(firstList, secondList)) { | ||
areSame = haveSameContents(firstList, secondList); | ||
} | ||
return areSame; | ||
}; | ||
const haveSameContents = function(firstList, secondList) { | ||
let listLength = firstList.length; | ||
let areSame = false; | ||
for (let i = 0; i <= listLength; i++) { | ||
if (firstList[i] !== secondList[i]) { | ||
areSame = false; | ||
break; | ||
} else areSame = true; | ||
} | ||
return areSame; | ||
}; | ||
const areSameLength = function(firstItem, secondItem) { | ||
let sameLength = true; | ||
if (firstItem.length !== secondItem.length) sameLength = false; | ||
return sameLength; | ||
}; | ||
const assertEqual = function(actual, expected) { | ||
if (actual === expected) console.log( | ||
`✅✅✅ Assertion Passed: ${actual} === ${expected}`); | ||
else console.log( | ||
`⛑️⛑️⛑️ Assertion Failed: ${actual} !== ${expected}`); | ||
}; | ||
// const ab = { a: "1", b: "2" }; | ||
@@ -103,11 +69,11 @@ // const ba = { b: "2", a: "1" }; | ||
console.log(eqObjects( | ||
{ a: { z: 1 }, b: 2 }, | ||
{ a: { z: 1 }, b: 2 })); // => true | ||
// console.log(eqObjects( | ||
// { a: { z: 1 }, b: 2 }, | ||
// { a: { z: 1 }, b: 2 })); // => true | ||
console.log(eqObjects( | ||
{ a: { y: 0, z: 1 }, b: 2 }, | ||
{ a: { z: 1}, b: 2 })); // => false | ||
console.log(eqObjects( | ||
{ a: { y: 0, z: 1 }, b: 2 }, | ||
{ a: 1, b: 2 })); // => false | ||
// console.log(eqObjects( | ||
// { a: { y: 0, z: 1 }, b: 2 }, | ||
// { a: { z: 1}, b: 2 })); // => false | ||
// console.log(eqObjects( | ||
// { a: { y: 0, z: 1 }, b: 2 }, | ||
// { a: 1, b: 2 })); // => false |
@@ -7,28 +7,24 @@ const findKey = function(object, callback) { | ||
const assertEqual = function(actual, expected) { | ||
if (actual === expected) console.log( | ||
`✅✅✅ Assertion Passed: ${actual} === ${expected}`); | ||
else console.log( | ||
`⛑️⛑️⛑️ Assertion Failed: ${actual} !== ${expected}`); | ||
}; | ||
module.exports = findKey; | ||
const result1 = findKey({ | ||
"Blue Hill": { stars: 1 }, | ||
"Akaleri": { stars: 3 }, | ||
"noma": { stars: 2 }, | ||
"elBulli": { stars: 3 }, | ||
"Ora": { stars: 2 }, | ||
"Akelarre": { stars: 3 } | ||
}, x => x.stars === 2); // => "noma" | ||
// Tests | ||
// const result1 = findKey({ | ||
// "Blue Hill": { stars: 1 }, | ||
// "Akaleri": { stars: 3 }, | ||
// "noma": { stars: 2 }, | ||
// "elBulli": { stars: 3 }, | ||
// "Ora": { stars: 2 }, | ||
// "Akelarre": { stars: 3 } | ||
// }, x => x.stars === 2); // => "noma" | ||
const result2 = findKey({ | ||
"Blue Hill": { stars: 1 }, | ||
"Akaleri": { stars: 3 }, | ||
"noma": { stars: 2 }, | ||
"elBulli": { stars: 3 }, | ||
"Ora": { stars: 2 }, | ||
"Akelarre": { stars: 3 } | ||
}, x => x.stars === 3); // => "Akaleri" | ||
// const result2 = findKey({ | ||
// "Blue Hill": { stars: 1 }, | ||
// "Akaleri": { stars: 3 }, | ||
// "noma": { stars: 2 }, | ||
// "elBulli": { stars: 3 }, | ||
// "Ora": { stars: 2 }, | ||
// "Akelarre": { stars: 3 } | ||
// }, x => x.stars === 3); // => "Akaleri" | ||
assertEqual(result1, 'noma'); | ||
assertEqual(result2, 'Akaleri'); | ||
// assertEqual(result1, 'noma'); | ||
// assertEqual(result2, 'Akaleri'); |
@@ -13,17 +13,12 @@ // FUNCTION IMPLEMENTATION | ||
const assertEqual = function(actual, expected) { | ||
if (actual === expected) console.log( | ||
`✅✅✅ Assertion Passed: ${actual} === ${expected}`); | ||
else console.log( | ||
`⛑️⛑️⛑️ Assertion Failed: ${actual} !== ${expected}`); | ||
}; | ||
module.exports = findKeyByValue; | ||
// DEBUGGING | ||
const bestTVShowsByGenre = { | ||
sci_fi: "The Expanse", | ||
comedy: "Brooklyn Nine-Nine", | ||
drama: "The Wire" | ||
}; | ||
// const bestTVShowsByGenre = { | ||
// sci_fi: "The Expanse", | ||
// comedy: "Brooklyn Nine-Nine", | ||
// drama: "The Wire" | ||
// }; | ||
assertEqual(findKeyByValue(bestTVShowsByGenre, "The Wire"), "drama"); | ||
assertEqual(findKeyByValue(bestTVShowsByGenre, "That '70s Show"), undefined); | ||
// assertEqual(findKeyByValue(bestTVShowsByGenre, "The Wire"), "drama"); | ||
// assertEqual(findKeyByValue(bestTVShowsByGenre, "That '70s Show"), undefined); |
@@ -12,48 +12,6 @@ // FUNCTION IMPLEMENTATION | ||
const assertArraysEqual = function(arrayOne, arrayTwo, expectedResult) { | ||
module.exports = flatten; | ||
assertEqual(eqArrays(arrayOne, arrayTwo), expectedResult); | ||
}; | ||
const assertEqual = function(actual, expected) { | ||
if (actual === expected) console.log( | ||
`✅✅✅ Assertion Passed: ${actual} === ${expected}`); | ||
else console.log( | ||
`⛑️⛑️⛑️ Assertion Failed: ${actual} !== ${expected}`); | ||
}; | ||
const eqArrays = function(firstList, secondList) { | ||
let areSame = false; | ||
if (areSameLength(firstList, secondList)) { | ||
areSame = haveSameContents(firstList, secondList); | ||
} | ||
return areSame; | ||
}; | ||
const haveSameContents = function(firstList, secondList) { | ||
let listLength = firstList.length; | ||
let areSame = false; | ||
for (let i = 0; i <= listLength; i++) { | ||
if (firstList[i] !== secondList[i]) { | ||
areSame = false; | ||
break; | ||
} else areSame = true; | ||
} | ||
return areSame; | ||
}; | ||
const areSameLength = function(firstItem, secondItem) { | ||
let sameLength = true; | ||
if (firstItem.length !== secondItem.length) sameLength = false; | ||
return sameLength; | ||
}; | ||
// console.log(flatten([1,2,3,[4,5],[6,[7,8],9],10])); | ||
// TEST CODE | ||
assertArraysEqual(flatten([1,2,3,[4,5],[6,[7,[8]],9],10]),[1,2,3,4,5,6,7,8,9,10], true); // => true | ||
// assertArraysEqual(flatten([1,2,3,[4,5],[6,[7,[8]],9],10]),[1,2,3,4,5,6,7,8,9,10], true); // => true |
@@ -15,46 +15,5 @@ // FUNCTION IMPLEMENTATION | ||
const assertArraysEqual = function(arrayOne, arrayTwo, expectedResult) { | ||
module.exports = letterPositions; | ||
assertEqual(eqArrays(arrayOne, arrayTwo), expectedResult); | ||
}; | ||
const assertEqual = function(actual, expected) { | ||
if (actual === expected) console.log( | ||
`✅✅✅ Assertion Passed: ${actual} === ${expected}`); | ||
else console.log( | ||
`⛑️⛑️⛑️ Assertion Failed: ${actual} !== ${expected}`); | ||
}; | ||
const eqArrays = function(firstList, secondList) { | ||
let areSame = false; | ||
if (areSameLength(firstList, secondList)) { | ||
areSame = haveSameContents(firstList, secondList); | ||
} | ||
return areSame; | ||
}; | ||
const haveSameContents = function(firstList, secondList) { | ||
let listLength = firstList.length; | ||
let areSame = false; | ||
for (let i = 0; i <= listLength; i++) { | ||
if (firstList[i] !== secondList[i]) { | ||
areSame = false; | ||
break; | ||
} else areSame = true; | ||
} | ||
return areSame; | ||
}; | ||
const areSameLength = function(firstItem, secondItem) { | ||
let sameLength = true; | ||
if (firstItem.length !== secondItem.length) sameLength = false; | ||
return sameLength; | ||
}; | ||
// TEST CODE | ||
assertArraysEqual(letterPositions("hello").e, [1], true); | ||
// assertArraysEqual(letterPositions("hello").e, [1], true); |
const head = require('./head'); | ||
const tail = require('./tail'); | ||
const middle = require('./middle'); | ||
const countLetters = require('./countLetters'); | ||
const letterPositions = require('./letterPositions'); | ||
const countOnly = require('./countOnly'); | ||
const flatten = require('./flatten'); | ||
const without = require('./without'); | ||
const takeUntil = require('./takeUntil'); | ||
const map = require('./map'); | ||
const findKeyByValue = require('./findKeyByValue'); | ||
const findKey = require('./findKey'); | ||
const eqObjects = require('./eqObjects'); | ||
const eqArrays = require('./eqArrays'); | ||
@@ -8,3 +19,14 @@ module.exports = { | ||
tail, | ||
middle | ||
middle, | ||
countLetters, | ||
letterPositions, | ||
countOnly, | ||
flatten, | ||
without, | ||
takeUntil, | ||
map, | ||
findKeyByValue, | ||
findKey, | ||
eqObjects, | ||
eqArrays, | ||
}; |
61
map.js
@@ -8,57 +8,18 @@ const map = function(array, callback) { | ||
return results | ||
return results; | ||
}; | ||
// FUNCTION IMPLEMENTATION | ||
const assertArraysEqual = function(actual, expected) { | ||
const inspect = require('util').inspect; | ||
if (eqArrays(actual, expected)) console.log( | ||
`✅✅✅ Assertion Passed: ${inspect(actual)} === ${inspect(expected)}`); | ||
else console.log( | ||
`⛑️⛑️⛑️ Assertion Failed: ${inspect(actual)} !== ${inspect(expected)}`); | ||
}; | ||
module.exports = map; | ||
const eqArrays = function(firstList, secondList) { | ||
let areSame = false; | ||
// const words = ["ground", "control", "to", "major", "tom"]; | ||
if (areSameLength(firstList, secondList)) { | ||
areSame = haveSameContents(firstList, secondList); | ||
} | ||
return areSame; | ||
}; | ||
// const results1 = map(words, word => word[0]); | ||
// const results2 = map(words, word => word[word.length - 1]); | ||
// const results3 = map(words, word => word[Math.floor((word.length - 1) / 2)]); | ||
// // console.log(results1); | ||
const haveSameContents = function(firstList, secondList) { | ||
let listLength = firstList.length; | ||
let areSame = false; | ||
for (let i = 0; i <= listLength; i++) { | ||
if (firstList[i] !== secondList[i]) { | ||
areSame = false; | ||
break; | ||
} else areSame = true; | ||
} | ||
return areSame; | ||
}; | ||
const areSameLength = function(firstItem, secondItem) { | ||
let sameLength = true; | ||
if (firstItem.length !== secondItem.length) sameLength = false; | ||
return sameLength; | ||
}; | ||
const words = ["ground", "control", "to", "major", "tom"]; | ||
const results1 = map(words, word => word[0]); | ||
const results2 = map(words, word => word[word.length - 1]); | ||
const results3 = map(words, word => word[Math.floor((word.length - 1) / 2)]); | ||
// console.log(results1); | ||
// TEST CODE | ||
assertArraysEqual(results1,['g','c','t','m','t']); // => pass | ||
assertArraysEqual(results2,['d','l','o','r','m']); // => fail | ||
assertArraysEqual(results3,['o','t','t','j','o']); // => fail | ||
// // TEST CODE | ||
// assertArraysEqual(results1,['g','c','t','m','t']); // => pass | ||
// assertArraysEqual(results2,['d','l','o','r','m']); // => fail | ||
// assertArraysEqual(results3,['o','t','t','j','o']); // => fail |
{ | ||
"name": "@jolduca/lotide", | ||
"version": "0.1.0", | ||
"version": "0.9.0", | ||
"description": "A recreation of lodash for learning purposes", | ||
@@ -5,0 +5,0 @@ "main": "lotide.js", |
@@ -31,2 +31,13 @@ # Lotide | ||
* `tail(...)`: gets everything BUT the first element of an array | ||
* `middle(...)`: gets the middle of odd and even arrays | ||
* `middle(...)`: gets the middle of odd and even arrays | ||
* `countLetters(...)`: counts the amount of chars in a string | ||
* `letterPositions(...)`: Gets the positions of every letter of a string and returns an object | ||
* `countOnly(...)`: Goes through an array of strings and counts only desired strings | ||
* `flatten(...)`: takes an array of elements and arrays and returns 1 total array containing all elements | ||
* `without(...)`: takes an array source and array of elements to remove from source. returns a copy of source array without elements from 2nd array | ||
* `takeUntil(...)`: takes an array and callback. Goes through array and sends each item to the callback. if callback returns false, adds element to an array. Otherwise, if returns true, will stop and return array of items that returned false upto that point | ||
* `map(...)`: Returns an array after manipulating each element using the provided callback | ||
* `findKeyByValue(...)`: takes an object and finds the first key that has the same value as provided | ||
* `findKey(...)`: takes an object and finds the first key that is the same as provided | ||
* `eqObjects(...)`: takes two objects and returns if they are the same or not. | ||
* `eqArrays(...)`: takes two arrays and returns if they are the same or not. |
@@ -1,2 +0,1 @@ | ||
const assertEqual = require('./assertEqual'); | ||
//Excludes the first element of array and passes the result back | ||
@@ -3,0 +2,0 @@ const tail = function(array) { |
@@ -10,59 +10,21 @@ const takeUntil = function(array, callback) { | ||
return slice; | ||
} | ||
const assertArraysEqual = function(actual, expected) { | ||
const inspect = require('util').inspect; | ||
if (eqArrays(actual, expected)) console.log( | ||
`✅✅✅ Assertion Passed: ${inspect(actual)} === ${inspect(expected)}`); | ||
else console.log( | ||
`⛑️⛑️⛑️ Assertion Failed: ${inspect(actual)} !== ${inspect(expected)}`); | ||
}; | ||
const eqArrays = function(firstList, secondList) { | ||
let areSame = false; | ||
module.exports = takeUntil; | ||
// TEST DATA | ||
// const data1 = [1, 2, 5, 7, 2, -1, 2, 4, 5]; | ||
// const results1 = takeUntil(data1, x => x < 0); | ||
// // console.log(results1); | ||
if (areSameLength(firstList, secondList)) { | ||
areSame = haveSameContents(firstList, secondList); | ||
} | ||
return areSame; | ||
}; | ||
// // console.log('---'); | ||
const haveSameContents = function(firstList, secondList) { | ||
let listLength = firstList.length; | ||
let areSame = false; | ||
// const data2 = ["I've", "been", "to", "Hollywood", ",", "I've", "been", "to", "Redwood"]; | ||
// const results2 = takeUntil(data2, x => x === ','); | ||
// // console.log(results2); | ||
for (let i = 0; i <= listLength; i++) { | ||
if (firstList[i] !== secondList[i]) { | ||
areSame = false; | ||
break; | ||
} else areSame = true; | ||
} | ||
return areSame; | ||
}; | ||
// // TEST CODE | ||
// assertArraysEqual(results1,[1,2,5,7,2]); // => pass | ||
// assertArraysEqual(results2,["I've", "been", "to", "Hollywood"]); // => pass | ||
const areSameLength = function(firstItem, secondItem) { | ||
let sameLength = true; | ||
if (firstItem.length !== secondItem.length) sameLength = false; | ||
return sameLength; | ||
}; | ||
const data1 = [1, 2, 5, 7, 2, -1, 2, 4, 5]; | ||
const results1 = takeUntil(data1, x => x < 0); | ||
// console.log(results1); | ||
// console.log('---'); | ||
const data2 = ["I've", "been", "to", "Hollywood", ",", "I've", "been", "to", "Redwood"]; | ||
const results2 = takeUntil(data2, x => x === ','); | ||
// console.log(results2); | ||
// TEST CODE | ||
assertArraysEqual(results1,[1,2,5,7,2]); // => pass | ||
assertArraysEqual(results2,["I've", "been", "to", "Hollywood"]); // => pass | ||
@@ -21,47 +21,6 @@ // FUNCTION IMPLEMENTATION | ||
}; | ||
// FUNCTION IMPLEMENTATION | ||
const assertArraysEqual = function(arrayOne, arrayTwo, expectedResult) { | ||
assertEqual(eqArrays(arrayOne, arrayTwo), expectedResult); | ||
}; | ||
module.exports = without; | ||
const assertEqual = function(actual, expected) { | ||
if (actual === expected) console.log( | ||
`✅✅✅ Assertion Passed: ${actual} === ${expected}`); | ||
else console.log( | ||
`⛑️⛑️⛑️ Assertion Failed: ${actual} !== ${expected}`); | ||
}; | ||
const eqArrays = function(firstList, secondList) { | ||
let areSame = false; | ||
if (areSameLength(firstList, secondList)) { | ||
areSame = haveSameContents(firstList, secondList); | ||
} | ||
return areSame; | ||
}; | ||
const haveSameContents = function(firstList, secondList) { | ||
let listLength = firstList.length; | ||
let areSame = false; | ||
for (let i = 0; i <= listLength; i++) { | ||
if (firstList[i] !== secondList[i]) { | ||
areSame = false; | ||
break; | ||
} else areSame = true; | ||
} | ||
return areSame; | ||
}; | ||
const areSameLength = function(firstItem, secondItem) { | ||
let sameLength = true; | ||
if (firstItem.length !== secondItem.length) sameLength = false; | ||
return sameLength; | ||
}; | ||
assertArraysEqual(without([1,2,3,4],[2]), [1,3,4], true); | ||
assertArraysEqual(without([1,2,3,4],['2']), [1,2,3,4], true); | ||
// assertArraysEqual(without([1,2,3,4],[2]), [1,3,4], true); | ||
// assertArraysEqual(without([1,2,3,4],['2']), [1,2,3,4], true); |
42
19323
497