Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

30
LINES

< > BotCompany Repo | #1000719 - dropLast function (drop last elements of array/list/string)

JavaX fragment (include)

static String[] dropLast(String[] a, int n) {
  n = Math.min(n, a.length);
  String[] b = new String[a.length-n];
  System.arraycopy(a, 0, b, 0, b.length);
  return b;
}

static <A> L<A> dropLast(L<A> l) {
  ret subList(l, 0, l(l)-1);
}

static <A> L<A> dropLast(int n, L<A> l) {
  ret subList(l, 0, l(l)-n);
}

static <A> L<A> dropLast(Iterable<A> l) {
  ret dropLast(asList(l));
}

static S dropLast(S s) {
  ret substring(s, 0, l(s)-1);
}

static S dropLast(S s, int n) {
  ret substring(s, 0, l(s)-n);
}

static S dropLast(int n, S s) {
  ret dropLast(s, n);
}

Author comment

Began life as a copy of #1000705

download  show line numbers  debug dex   

Travelled to 9 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, tslmcundralx, tvejysmllsmz

No comments. add comment

Snippet ID: #1000719
Snippet name: dropLast function (drop last elements of array/list/string)
Eternal ID of this version: #1000719/5
Text MD5: 35f5da8828fa4377051fd05ee0812cb1
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-10-21 17:32:55
Source code size: 595 bytes / 30 lines
Pitched / IR pitched: No / No
Views / Downloads: 410 / 664
Version history: 4 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1000719 & http://1000719.tinybrain.de