[Free] Lists Extension an extension for arrange in ascending order, descending order, get min/max value

My first Extension

Name: Lists

PublishOn: 4-07-2021

Version: 1.0

Usage: Convert number and text in ascending order, Convert number and text in descending order, Find maximum number from a list, Find minimum number from a list, Reverse a list

Blocks:

Screenshot (158)

HowToUse:

Thanking: Thanks a lot to @shreyash extension build with rush a new and improved way of building extension, thanks a lot to @Aarush_Kumar he gives me the tutorial of java

DownloadLink: v1 com.faraz.Lists.aix (3.8 KB)
v2 com.faraz.Lists.aix (3.8 KB)

JavaSource

package com.faraz.Lists;

import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.errors.YailRuntimeError;
import com.google.appinventor.components.runtime.util.YailList;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;

public class Lists extends AndroidNonvisibleComponent {

public Lists(ComponentContainer container) {
super(container.$form());
}

@SimpleFunction(description = "")
public Object Sort(List list) {
List sort = new ArrayList(list);
Collections.sort(sort);
return sort;
}

@SimpleFunction(description = "")
public Object Reverse(List list) {
List reverse = new ArrayList(list);
Collections.reverse(reverse);
return reverse;
}

@SimpleFunction(description = "")
public Object MaximumNumber(List list) {
List max = new ArrayList(list);
Collections.sort(max);
return max.get(max.size() - 1);
}

@SimpleFunction(description = "")
public Object MinimumNumber(List list) {
List min = new ArrayList(list);
Collections.sort(min);
return min.get(0);
}
}

6 Likes

Nice Extension @Faraz_Firoz, Good Job :+1: :sunglasses: :+1:

1 Like

Thank you @Salman_Dev

1 Like

Add this extension in your all extension from AppInventor topic

Oh, i'm sorry i can't do that

1 Like

Your max and min functions also work on text lists (e.g. max(["a","b","c"]) = c)

I see it will also sort a list of lists but only by the first item in the sublist. It doesn't sort the sublists.

Will also sort a dictionary but only by keys

Also the original list is not sorted, a new temporary list is created once sorted

Can you show me

List of Lists
image
image

This is easily overcome by doing:

image

Dictionary

image
image

1 Like

https://community.appinventor.mit.edu/uploads/default/original/3X/c/8/c8896b856b41aede297c9f14c715e4f64b003409.png
Is this work by doing this

1 Like

Original list not changed (this is not a bad thing, just useful to know)

image

image

1 Like

I do not understand what are you saying

1 Like

When you apply the sort, it does not change the original list, it outputs a new list (sorted).

1 Like

On the place of two make a list use this
Capture

1 Like

I don't think that's a problem, I guess all extensions work this way.
Do you have any other way to return the list from an extension?

lists

2 Likes

As I said...

1 Like

@TIMAI2 has this extension passed the evaluation?

A power user has released it yes. Unfortunately before we had an aix to test, so now we do it here....

1 Like

Yes I passed the evaluation

1 Like

I don't think changing the original variable is possible through an extension.

2 Likes

Yes, I missed aix :joy: The reason was that there was java source in the approved post. I found that these methods must work :grin:.

1 Like