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

13
LINES

< > BotCompany Repo | #1023874 // minOfIntArray_withIndex

JavaX fragment (include)

1  
// return index and value
2  
static Pair<Int> minOfIntArray_withIndex(int[] a) {
3  
  if (a == null || a.length == 0) null;
4  
  int n = a.length, x = a[0], best = 0;
5  
  for (int i = 1; i < n; i++) {
6  
    int y = a[i];
7  
    if (y < x) {
8  
      x = y;
9  
      best = i;
10  
    }
11  
  }
12  
  ret pair(best, x);
13  
}

Author comment

Began life as a copy of #1023863

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1023874
Snippet name: minOfIntArray_withIndex
Eternal ID of this version: #1023874/2
Text MD5: 51fec3a7b05db7c3a154a1c97dff2439
Author: stefan
Category: javax / maths
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-07-11 00:06:58
Source code size: 298 bytes / 13 lines
Pitched / IR pitched: No / No
Views / Downloads: 130 / 165
Version history: 1 change(s)
Referenced in: [show references]