{"_id":"@alhajahmed/lotide-v2","name":"@alhajahmed/lotide-v2","dist-tags":{"latest":"2.0.0"},"versions":{"2.0.0":{"name":"@alhajahmed/lotide-v2","version":"2.0.0","description":"lotide version 2 is mini clone of the Lodash library","main":"assertArraysEqual-v2.js","directories":{"test":"test"},"scripts":{"test":"mocha"},"repository":{"type":"git","url":"git+https://github.com/Alhajahmed/lotide-v2.git"},"author":{"name":"Ahmed Alhajahmed"},"license":"ISC","bugs":{"url":"https://github.com/Alhajahmed/lotide-v2/issues"},"homepage":"https://github.com/Alhajahmed/lotide-v2#readme","devDependencies":{"chai":"^4.3.7","mocha":"^9.2.2"},"gitHead":"76506201a78a763c66e8eebc7db3fa5dc1b4bda3","_id":"@alhajahmed/lotide-v2@2.0.0","_nodeVersion":"12.18.4","_npmVersion":"6.14.6","dist":{"integrity":"sha512-RM76ZYCzQKCs7Elh2omj/Ug838vQ8/ZA5r0bCrR02SE61S5LU4Hv6sMoVeCRl/Wis+uOeY7KXBpJPi/jkACZ/g==","shasum":"37fd03398cac78bdda04f771662c3ce676874f25","tarball":"https://registry.npmjs.org/@alhajahmed/lotide-v2/-/lotide-v2-2.0.0.tgz","fileCount":27,"unpackedSize":26890,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAbr5eLBnoCLEX+AFhMqfvj4HpmMLA78L7K6nZVCt9OZAiEA1IvZ5FoeYscKhtfPilvIj4UhNITUMiR3xgdrBv/koug="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkPGbXACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrA3xAAogAnPDSh4hUyq5RWgCzMHxEaFObb8DnDCO0XKxoQpnwB03kl\r\nRW95jS1JBCpGFsR1T12cRS1h1vcJZo2Q4v65WX921UWz2MgIxZhWiQHfJRkC\r\n5swvcY8Eoe6OJKviUN7fK2LaxiDJqAcwvtBo1mHnVGCzksjdPYrzlsCPittv\r\nXsw4ZX4r58RW+/NcP/vXWXT2KjqdopODemjm/VhspxIrB0NQtgGu/hq4TWN3\r\nqDjISbfY1OReSYhZMU7AnAf8qwwMbJv4wlSeg6wmcFYu3EUXrK+TXbWZo+aM\r\neNJS/3y6twhh/BIzBYQzPGLgweJnO1VlijiRoAvF/D/c67tb5kBlGABbRk4q\r\ncnLvPjgYGmtfFg7+pV9Xzpg5Mht9X+MMcUi2uWDqAdH5U8+nmipJi0e8Ff+n\r\nfzXIRKq0+oQ2dZyueLcRxmQhCBsKP9E67tZtJOvEnWVaRRIzFuxSZb7z0q/7\r\n8T6DoMznOQCcHs5c5+QM8tP2vETJzqSeMBYJ/eJ1HOyzByLgJtQF2TEcr82Z\r\ndXc8cW4MRPIU9Po9bhoMhC0OlW2d8pth7RwjpJLW/rivfMOfKwYsaqC1LpaP\r\nbqnuutaZ26RPGXeK0sNM3dpY2YnCrH4z53sfq0RxzC0/l3s+4dtlLKxjUykx\r\n9eqvQ5MmdxsdZGYQ4B3jygGciikl1DqBiNk=\r\n=nuje\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"alhajahmed","email":"ahmed91alhaj@gmail.com"},"maintainers":[{"name":"alhajahmed","email":"ahmed91alhaj@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/lotide-v2_2.0.0_1681680087279_0.5897589068198958"},"_hasShrinkwrap":false}},"time":{"created":"2023-04-16T21:21:27.224Z","2.0.0":"2023-04-16T21:21:27.431Z","modified":"2023-04-16T21:21:27.620Z"},"maintainers":[{"name":"alhajahmed","email":"ahmed91alhaj@gmail.com"}],"description":"lotide version 2 is mini clone of the Lodash library","homepage":"https://github.com/Alhajahmed/lotide-v2#readme","repository":{"type":"git","url":"git+https://github.com/Alhajahmed/lotide-v2.git"},"author":{"name":"Ahmed Alhajahmed"},"bugs":{"url":"https://github.com/Alhajahmed/lotide-v2/issues"},"license":"ISC","readme":"# Lotide\n\nA mini clone of the [Lodash](https://lodash.com) library.\n\n## Purpose\n\n**_BEWARE:_ This library was published for learning purposes. It is _not_ intended for use in production-grade software.**\n\nThis project was created and published by me as part of my learnings at Lighthouse Labs.\n\n## Usage\n\n**Install it:**\n\n`npm install @alhajahmed/lotide-v2`\n\n**Require it:**\n\n`const _ = require('@alhajahmed/lotide-v2');`\n\n**Call it:**\n\n`const results = _.tail([1, 2, 3]) // => [2, 3]`\n\n## Documentation\n\nThe following functions are currently implemented:\n\n- **head:** returns the first element of an array.\n\n```\nconst head = function (array) {\n  if (array.length === 0) {\n    return undefined;\n  } else {\n    return array[0];\n  }\n};\n```\n\n- **tail:** returns a new array containing all the elements of the input array except the first one.\n\n```\nconst tail = function (array) {\n  if (array.length === 0) {\n    return [];\n  } else {\n    return array.slice(1);\n  }\n};\n```\n\n- **middle:** returns an array containing the middle element(s) of the input array.\n\n```\nconst middle = function (array) {\n  const middleElements = [];\n  middleIndex = Math.floor(array.length / 2);\n  if (array.length <= 2) {\n    return middleElements;\n  } else if (array.length % 2 !== 0) {\n    middleElements.push(array[middleIndex]);\n  } else {\n    middleElements.push(array[middleIndex - 1], array[middleIndex]);\n  }\n  return middleElements;\n};\n```\n\n- **assertArraysEqual:** checks if two arrays are equal and logs a message to the console.\n\n```\nconst assertArraysEqual = function (firstArray, secArray) {\n  if (eqArrays(firstArray, secArray)) {\n    console.log(`✅ Assertion Passed: [${firstArray}] === [${secArray}]`);\n  } else {\n    console.log(`❌ Assertion Failed: [${firstArray}] !== [${secArray}]`);\n  }\n};\n```\n\n- **assertEqual:** checks if two primitive values are equal and logs a message to the console.\n\n```\nconst assertEqual = function (actual, expected) {\n  if (actual === expected) {\n    console.log(`✅ Assertion Passed: ${actual} === ${expected}`);\n    return true;\n  } else {\n    console.log(`❌ Assertion Failed: ${actual} !== ${expected}`);\n    return false;\n  }\n};\n```\n\n- **assertObjectsEqual:** checks if two objects are equal and logs a message to the console.\n\n```\nconst inspect = require(\"util\").inspect;\nconst assertObjectsEqual = function (actual, expected) {\n  if (eqObjects(actual, expected)) {\n    console.log(\n      `✅ Assertion Passed: ${inspect(actual)} === ${inspect(expected)}`\n    );\n  } else {\n    console.log(\n      `❌ Assertion Failed: ${inspect(actual)} !== ${inspect(expected)}`\n    );\n  }\n};\n```\n\n- **eqObjects:** checks if two objects are equal (i.e., have the same keys and values).\n\n```\nconst eqObjects = function (object1, object2) {\n  const obj1Keys = Object.keys(object1);\n  const obj2Keys = Object.keys(object2);\n  if (obj1Keys.length !== obj2Keys.length) {\n    return false;\n  }\n  for (let key of obj1Keys) {\n    const val1 = object1[key];\n    const val2 = object2[key];\n    if (Array.isArray(val1) && Array.isArray(val2)) {\n      if (!eqArrays(val1, val2)) {\n        return false;\n      }\n    } else if (val1 !== val2) {\n      return false;\n    }\n  }\n  return true;\n};\n```\n\n- **countLetters:** takes a string as input and returns an object that counts the number of occurrences of each letter in the string.\n\n```\nconst countLetters = function (sentence) {\n  const letterCounts = {};\n  const letters = sentence.split(\" \").join(\"\");\n  for (let letter of letters) {\n    if (letterCounts[letter]) {\n      letterCounts[letter]++;\n    } else {\n      letterCounts[letter] = 1;\n    }\n  }\n  return letterCounts;\n};\n```\n\n- **countOnly:** takes an array and an object as input and returns an object that counts the number of occurrences of the keys that are true in the input object.\n\n```\nonst countOnly = function (allItems, itemsToCount) {\n  const results = {};\n  for (const item of allItems) {\n    if (itemsToCount[item]) {\n      if (results[item]) {\n        results[item]++;\n      } else {\n        results[item] = 1;\n      }\n    }\n  }\n  return results;\n};\n```\n\n- **eqArrays:** checks if two arrays are equal (i.e., have the same elements in the same order).\n\n```\nconst eqArrays = function (firstArray, secArray) {\n  if (firstArray.length !== secArray.length) {\n    return false;\n  }\n  for (let i = 0; i < firstArray.length; i++) {\n    if (firstArray[i] !== secArray[i]) {\n      return false;\n    }\n  }\n  return true;\n};\n```\n\n- **findKey:** takes an object and a callback function as input and returns the first key in the object for which the callback function returns a truthy value.\n\n```\nconst findKey = (obj, callback) => {\n  for (const key of Object.keys(obj)) {\n    if (callback(obj[key])) {\n      return key;\n    }\n  }\n  return undefined;\n};\n```\n\n- **findKeyByValue:** takes an object and a value as input and returns the first key in the object that has the given value.\n\n```\nconst findKeyByValue = function (obj, value) {\n  for (let key of Object.keys(obj)) {\n    if (obj[key] === value) {\n      return key;\n    }\n  }\n  return undefined;\n};\n```\n\n- **flatten:** takes an array as input and returns a flattened version of the array (i.e., an array with no nested arrays).\n\n```\nconst flatten = function (array) {\n  const flattened = [];\n  for (let ele of array) {\n    if (Array.isArray(ele)) {\n      for (let nestedEle of ele) {\n        flattened.push(nestedEle);\n      }\n    } else {\n      flattened.push(ele);\n    }\n  }\n  return flattened;\n};\n```\n\n- **letterPositions:** takes a string as input and returns an object that maps each letter to an array of its positions in the string.\n\n```\nconst letterPositions = function (sentence) {\n  const result = {};\n  for (let i = 0; i < sentence.length; i++) {\n    const char = sentence[i];\n    if (char !== \" \") {\n      if (!result[char]) {\n        result[char] = [i];\n      } else {\n        result[char].push(i);\n      }\n    }\n  }\n  return result;\n};\n```\n\n- **map:** takes an array and a callback function as input and returns a new array containing the values returned by the callback function for each element in the input array.\n\n```\nconst map = function (array, callback) {\n  const results = [];\n  for (let item of array) {\n    results.push(callback(item));\n  }\n  return results;\n};\n```\n\n- **takeUntil:** takes an array and a callback function as input and returns a new array containing the elements of the input array up to (but not including) the first element for which the callback function returns a truthy value.\n\n```\nconst takeUntil = function (array, callback) {\n  for (let i = 0; i < array.length; i++) {\n    if (callback(array[i])) {\n      return array.slice(0, i);\n    }\n  }\n  return array.slice();\n};\n```\n\n- **without:** takes two arrays as input and returns a new array containing all the elements of the first array that are not present in the second array.\n\n```\nconst without = function (source, itemsToRemove) {\n  const result = [];\n  for (let element of source) {\n    if (!itemsToRemove.includes(element)) {\n      result.push(element);\n    }\n  }\n  return result;\n};\n```\n","readmeFilename":"README.md"}