How to Get Index(Of:) to Return Multiple Indices

How to get index(of:) to return multiple indices?

You might use a combination of enumerated and compactMap:

let indexArray = group.enumerated().compactMap {
$0.element == "A" ? $0.offset : nil
}
print(indexArray) // [10, 12, 13, 27]

EcmaScript6 findIndex method, can it return multiple values?

You can use .map() method here like:

let ages = [12, 15, 18, 17, 21];let indexes = ages.map((elm, idx) => elm >= 18 ? idx : '').filter(String);console.log( indexes );

How to return multiple array element index values as an Int in swift 4

    for (index, value) in array.enumerated() {
if value == "Apples" {
print(index)
}
}

you can store it in a different variable or store it in array.you will get the index of string "Apple" from the given array. Hope this will help you.

indexOf similar function to return multiple appearance in javascript

With one loop :

function indexesOf(arr, target) {
let index = [];
// For each element, index pushed in index[]
arr.forEach((el, i) => {
if (el === target) index.push(i)
});
return index;
}
alert(indexesOf([1, 2, 4, 2], 2)); // -> 1, 3

With two loops :

function indexesOf(arr, target) {
// Map matching elements to their index, and others to null.
return arr.map(function (el, i) { return (el === target) ? i : null; })
// Throw out the nulls.
.filter(function (x) { return x !== null; });
}

alert(indexesOf([1, 2, 4, 2], 2)); // -> 1, 3

How to get index of multiple maximum value in List

Something like this:

int max = len.stream().max(Integer::compareTo).get();
System.out.println(IntStream.range(0, len.size()).filter(ix -> len.get(ix).intValue() == max).boxed()
.collect(Collectors.toList()));

Finding multiple indexes from source string

    var indexs = "Prashant".MultipleIndex('a');

//Extension Method's Class
public static class Extensions
{
static int i = 0;

public static int[] MultipleIndex(this string StringValue, char chChar)
{

var indexs = from rgChar in StringValue
where rgChar == chChar && i != StringValue.IndexOf(rgChar, i + 1)
select new { Index = StringValue.IndexOf(rgChar, i + 1), Increament = (i = i + StringValue.IndexOf(rgChar)) };
i = 0;
return indexs.Select(p => p.Index).ToArray<int>();
}
}

Excel lookup index that can return multiple results

Something like the following should work:

=LET(data, List_State_11.18.2021!J:J, filterlist, List_State_11.18.2021!A:A, lookup, A2, TRANSPOSE(FILTER(data, filterlist=lookup, "No Results")))

For use with TEXTJOIN, you wouldn't need to transpose the results

=LET(data, List_State_11.18.2021!J:J, filterlist, List_State_11.18.2021!A:A, lookup, A2, results, FILTER(data, filterlist=lookup,"NA"), TEXTJOIN("; ", TRUE, results))

Returning multiple index values from an array using Javascript

You could write a function like this:

function indexesOf(myWord, myLetter)
{
var indexes = new Array();
for(var i = 0; i < myWord.length; i++)
{
if(myWord.charAt(i) == myLetter)
{
indexes.push(i);
}
}
return indexes;
}
console.log(indexesOf("tree", "e"));


Related Topics



Leave a reply



Submit