Giter Club home page Giter Club logo

array-toolkit's People

Contributors

mrname5 avatar renickbell avatar reprimande avatar yiler7274 avatar

Watchers

 avatar

Forkers

reprimande

array-toolkit's Issues

getMinIndex and getMaxIndex have bad repetition

Both of these functions use the same subroutine. We want a more generic function which takes a function as an argument to use as the base for these two. These two should be specific cases of calling that function. Include all 3 functions in the library.

add findClosestLarger, implement in terms of findClosestBy

there is a findClosestSmaller. please add a similar function called findClosestLarger.

reimplement both in terms of a function called findClosestBy which takes a function as an argument and allows us to do custom findClosest functions.

safeSplice function cannot splice in a flattened array

let testNumArr = [1, 3, 6, 2, 7]

console.log(A.safeSplice(testNumArr, 2, 1, [5, 8, 8])) //[ 1, [ 5, 8, 8 ], 2, 7 ]
console.log(A.safeSplice(testNumArr, 2, 1, ...[5, 8, 8])) //[ 1, 5, 2, 7 ]
//none of those work

I should do this: [ 1, 5, 8, 8 , 2, 7 ]
when this is the input: console.log(A.safeSplice(testNumArr, 2, 1, ...[5, 8, 8]))

Write JSDoc

Write JSDoc for every function for better code completion/hint and other assistance in modern IDEs such as VSCode.

For instance:

/**
 * Takes the length the array should be changed into as argument.
 * If array longer, will shorten array. If array shorter will loop the array until desiredLength.
 * (Generated with Chatgpt)
 * @param {number} number the desired length
 * @param {Array} array the array to modify
 * @example console.log(adjustArrayLength(5, [0,1,2])) // [......]
 */
function adjustArrayLength(number, array) {
    let arrayLength = array.length;
    if (arrayLength === number) {
        return array;
    } else if (arrayLength < number) {
        let numCopies = Math.ceil(number / arrayLength);
        return array.concat(...Array(numCopies).fill(array)).slice(0, number);
    } else {
        return array.slice(0, number);
    }
}

resizeArray has a bad name

The name of the function "resizeArray" isn't the most appropriate name for this function. We need to improve it. Can someone suggest a better name?

Leverage ES6 import/export Pattern

Would it be better to use ES6 import and export pattern in terms of code maintainability and clarity?

// arrayTransformations.js
export const adjustArrayLength = (number, array) => {
    //...
}
export const anotherFunction = () => {}
// ...

// index.js
export {adjustArrayLength, anotherFunction} from "./arrayTransformations.js";

// usage
import {adjustArrayLength, anotherFunction} from "array-toolkit";

fix removeItem function

We have three potential types of removeItem:

  1. removes all instances of something
  2. removes the first instance of something
  3. removes the item at a particular index

Please implement and choose appropriate function names.

comment got dropped for shuffle

The comment describing the original source for shuffle is still in Konduktiva combined.js and missing from arrayTransformations.js here.

removeAllInstances function does not work with objects.

let testNumArr = [1, 3, 6, 2, 7]
let testObj = {name: 'jill'}
let testMixArr = [1, 3, 'string', [1, 2], {name: 'bob'}, testObj, null, undefined]

console.log(A.removeAllInstance(testMixArr, {name: 'jill'}))
/*
[
  1,
  3,
  'string',
  [ 1, 2 ],
  { name: 'bob' },
  { name: 'jill' },
  null,
  undefined
]
*/

Should it remove { name: 'jill' }?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.