Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

potential new method: cull an array to every nth element? #706

Closed
kurttheviking opened this issue Sep 12, 2014 · 3 comments
Closed

potential new method: cull an array to every nth element? #706

kurttheviking opened this issue Sep 12, 2014 · 3 comments

Comments

@kurttheviking
Copy link

I work with time series data quite often and I find myself writing something like the following regularly; I wonder if it's worth adding as a core method, supporting objects, optimizing for better performance internally (especially with the _rtl option). If interested, I am happy to expand and work on a related PR.

//  returns an array of every freq'th item
// _rtl starts the sampling from the right-side of the array
function cull (list, freq, _rtl) {
  list = _.isArray(list) ? list.slice(0) : [];
  freq = freq || 1;

  if (_rtl) {
    list.reverse();
  }

  list = _.filter(list, function (val, i) {
    if (i%freq === 0) {
      return val;
    }
  });

  return _rtl ? list.reverse() : list;
}

The result is similar to sample, except with a deterministic output.

@jdalton
Copy link
Member

jdalton commented Sep 12, 2014

@kurttheviking For the time being we'll let lodash-contrib tackle this. If the feature becomes a popular request we'll totally reconsider.

@jdalton jdalton closed this as completed Sep 12, 2014
@kurttheviking
Copy link
Author

@jdalton sounds good; appreciate the quick response; thanks for the heads up...we will check it out

@lock
Copy link

lock bot commented Jan 20, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants