Flutter convert array format - arrays
How to convert this below array:
[{timeNameID: [2, 4, 5, 6, 7, 8], alarmIDAdzan: [4, 5, 5, 5, 5, 5], alarmIDIqamah: [5, 5, 4, 4, 4, 4]}]
to be:
[
{ timeNameID: '2', alarmIDAdzan: '4', alarmIDIqamah: '5' },
{ timeNameID: '4', alarmIDAdzan: '5', alarmIDIqamah: '5' },
{ timeNameID: '5', alarmIDAdzan: '5', alarmIDIqamah: '4' },
{ timeNameID: '6', alarmIDAdzan: '5', alarmIDIqamah: '4' },
{ timeNameID: '7', alarmIDAdzan: '5', alarmIDIqamah: '4' },
{ timeNameID: '8', alarmIDAdzan: '5', alarmIDIqamah: '4' }
]
Here is my code so far:
var makeArray = [
{
'timeNameID': selectedTimeNameID,
'alarmIDAdzan': selectedAlarmAdzanID,
'alarmIDIqamah': selectedAlarmIqamahID
}
];
Is there any way to do the convert?
You could try this
var a = [{"timeNameID": [2, 4, 5, 6, 7, 8], "alarmIDAdzan": [4, 5, 5, 5, 5, 5], "alarmIDIqamah": [5, 5, 4, 4, 4, 4]}];
var b = Iterable<int>.generate(a[0]["timeNameID"]!.length).map((e) =>
{"timeNameID":a[0]["timeNameID"]![e],"alarmIDAdzan":a[0]["alarmIDAdzan"]![e],"alarmIDIqamah":a[0]["alarmIDIqamah"]![e]});
print(b);
this prints
({timeNameID: 2, alarmIDAdzan: 4, alarmIDIqamah: 5}, {timeNameID: 4, alarmIDAdzan: 5, alarmIDIqamah: 5}, {timeNameID: 5, alarmIDAdzan: 5, alarmIDIqamah: 4}, ..., {timeNameID: 7, alarmIDAdzan: 5, alarmIDIqamah: 4}, {timeNameID: 8, alarmIDAdzan: 5, alarmIDIqamah: 4})
Note thought, that this requires the fields to exist and all be the same length. It will lead to errors if it's not the case
Related
How can I swap two bits starting from MSB?
I'm looking for a way to swap 2 bits at a given position but counting starts from MSB(most significant bit) to LSB (least significant bit). Lets say i have position p1 = 0 and p2 = 2 and my number is 1000 = 8 . The result should be 0010 . I tried this piece of code but it swaps the bits starting from LSB to MSB . How do I "reverse" the process? unsigned int bit1 = (num >> p1) & 1; unsigned int bit2 = (num >> p2) & 1; unsigned int x = (bit1 ^ bit2); x = (x << p1) | (x << p2); result = num ^ x;
By your example, I will assume you mean to start numbering bits from the MSB of the number value. That is, given: 00010100 ↑ msb == most significant bit in the number In that case, you need a way to count the bit index of the MSB. There are actually processor instructions you can use to do that, and both MSVC and GCC (and Clang) provide special functions to access that functionality... ...but you don’t need that. Instead, just write yourself a function: int index_of_msb( unsigned long value ) { ... } Remember that you can shift a number down by one bit at a time. As long as the number is not zero, you have at least one set bit left. 1 0 1 0 0 0 → 1 0 1 0 0 (1 shift) → 1 0 1 0 (2 shifts) → 1 0 1 (3 shifts) → 1 0 (4 shifts) → 1 (5 shifts) → 0 Five shifts → bit 5 is MSB. Now you can convert your bit positions to the standard shift offsets. p1 = p_msb - p1; p2 = p_msb - p2; What remains to do is use your standard bit operators to swap the two bit values.
Four bits is small enough that you can use a 256-byte table: unsigned char SwapBits(unsigned char number, int p0, int p1) { static const unsigned char Table[16][4][4] = { { { 0, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0, 0} }, { { 1, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0, 0} }, { { 2, 1, 0, 0}, { 1, 2, 2, 2}, { 0, 2, 2, 2}, { 0, 2, 2, 2} }, { { 3, 3, 1, 1}, { 3, 3, 2, 2}, { 1, 2, 3, 3}, { 1, 2, 3, 3} }, { { 4, 2, 1, 0}, { 2, 4, 4, 4}, { 1, 4, 4, 4}, { 0, 4, 4, 4} }, { { 5, 3, 5, 1}, { 3, 5, 6, 5}, { 5, 6, 5, 4}, { 1, 5, 4, 5} }, { { 6, 6, 3, 2}, { 6, 6, 5, 4}, { 3, 5, 6, 6}, { 2, 4, 6, 6} }, { { 7, 7, 7, 3}, { 7, 7, 7, 5}, { 7, 7, 7, 6}, { 3, 5, 6, 7} }, { { 8, 4, 2, 1}, { 4, 8, 8, 8}, { 2, 8, 8, 8}, { 1, 8, 8, 8} }, { { 9, 5, 3, 9}, { 5, 9, 9, 12}, { 3, 9, 9, 10}, { 9, 12, 10, 9} }, { {10, 6, 10, 3}, { 6, 10, 12, 10}, {10, 12, 10, 9}, { 3, 10, 9, 10} }, { {11, 7, 11, 11}, { 7, 11, 13, 14}, {11, 13, 11, 11}, {11, 14, 11, 11} }, { {12, 12, 6, 5}, {12, 12, 10, 9}, { 6, 10, 12, 12}, { 5, 9, 12, 12} }, { {13, 13, 7, 13}, {13, 13, 11, 13}, { 7, 11, 13, 14}, {13, 13, 14, 13} }, { {14, 14, 14, 7}, {14, 14, 14, 11}, {14, 14, 14, 13}, { 7, 11, 13, 14} }, { {15, 15, 15, 15}, {15, 15, 15, 15}, {15, 15, 15, 15}, {15, 15, 15, 15} }, }; return Table[number][p0][p1]; }
Working with Charts in motion [Animating chart]
I have created a areaspline chart using highcharts library and making it animated with play/pause button transition between weeks of data Ref. https://www.highcharts.com/blog/tutorials/176-charts-in-motion/ jsfiddle Ref. https://jsfiddle.net/larsac07/wkev75nL/?utm_source=website&utm_medium=embed&utm_campaign=wkev75nL in the above example, we are animating the chart week wise dataSet used : dataSequence = [ { name: 'Week 1', data: [1, 2, 2, 1, 1, 2, 2] }, { name: 'Week 2', data: [6, 12, 2, 3, 3, 2, 2] }, { name: 'Week 3', data: [4, 5, 6, 5, 5, 4, 9] }, { name: 'Week 4', data: [5, 5, 6, 6, 5, 6, 6] }, { name: 'Week 5', data: [6, 7, 7, 6, 6, 6, 7] }, { name: 'Week 6', data: [8, 9, 9, 8, 8, 8, 9] }, { name: 'Week 7', data: [9, 10, 4, 10, 9, 9, 9] }, { name: 'Week 8', data: [1, 10, 10, 10, 10, 11, 11] }, { name: 'Week 9', data: [11, 11, 12, 12, 12, 11, 11] } ] I don't want change chart on play button click I want animate the data points 11 data point for week1 to same data point but different value on y axis for week2 xAxis = ["week1", "Week2", ..... ], yAxis = [[1,2,3,4,5,6,7,8,9,10,11], [3,5,7,8,2,1,5,7,6,1,10], ....] on the play button it would transit between week1 then will go to week 2 and so till last week number available. Trying to have something like this Ref. https://aatishb.com/covidtrends/ this chart is plotted using this dataset for series Highcharts.chart("container", { chart: { type: "areaspline" }, tooltip: { shared: true, valueSuffix: " units" }, xAxis: { categories: [ "Week 1", "Week 2", "Week 3", "Week 4", "Week 5", "Week 6", "Week 7" ] }, yAxis: { title: { text: "Index" } }, legend: { layout: "horizontal", align: "right", verticalAlign: "top", x: 50, y: 50, floating: true, borderWidth: 1, backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || "#FFFFFF" }, plotOptions: { areaspline: { fillOpacity: 0.5 } }, credits: { enabled: false }, series: [ { name: "By week", data: dataSequence[value].data.slice() }, { type: "spline", name: "Topic 1", data: [3, 2, 1, 3, 4, 7, 8] }, { type: "spline", name: "Topic 2", data: [1, 5, 1, 3, 4, 7, 8] }, { type: "spline", name: "Topic 3", data: [3, 7, 1, 3, 4, 7, 8] }, { type: "spline", name: "Topic 4", data: [5, 1, 1, 3, 4, 7, 8] }, { type: "spline", name: "Topic 5", data: [7, 3, 1, 3, 4, 7, 8] }, { type: "spline", name: "Topic 6", data: [9, 2, 1, 3, 4, 7, 8] }, { type: "spline", name: "Topic 7", data: [11, 8, 1, 3, 4, 7, 8] }, { type: "spline", name: "Topic 8", data: [13, 11, 1, 3, 4, 7, 8] }, { type: "spline", name: "Topic 9", data: [15, 7, 1, 3, 4, 7, 8] }, { type: "spline", name: "Topic 10", data: [7, 5, 1, 3, 4, 7, 8] } ], title: { text: "" }, subtitle: { text: "Efficiency Index of Topics" } }); this my update function in react update(increment) { var input = $("#play-range")[0]; var output = $("#play-output")[0]; if (increment) { input.value = parseInt(input.value) + increment; } output.innerHTML = this.state.dataSequence[input.value].name; this.setState({ value: input.value }); if (input.value >= input.max) { // Auto-pause this.pause(); this.setState( { value: 0 }, () => { output.innerHTML = this.state.dataSequence[0].name; } ); } } the whole chart is plotted at once, I need something that it should transit first, it plots all data points for week1 then week 2 after that week 3 when I click on the play button
You need to start with an empty data and use addPoint method in the update function: function update(increment) { var input = $('#play-range')[0], output = $('#play-output')[0], increment; chart.series[0].addPoint(dataSequence[input.value].data[actualPointIndex]); actualPointIndex += increment; if (actualPointIndex === 6) { actualPointIndex = 0; input.value = parseInt(input.value) + increment; } output.innerHTML = dataSequence[input.value].name; // Output value if (input.value >= input.max) { // Auto-pause pause($('#play-pause-button')[0]); } } Live demo: https://jsfiddle.net/BlackLabel/stpxyfca/ API Reference: https://api.highcharts.com/class-reference/Highcharts.Series#addPoint
VBA Optimize array handling
I ran up against the limit of the amount of items I could put into a single array... I also ran into the limit of the number of line continuation characters I was able to use... So I had to break this function into two arrays. I really hate that I had to use two arrays, but it does work. Does anyone have any suggestions how I could tighten this code up? Maybe take out the "insert character into a cell" step and just jump right to the color?... Have fun Sub Why_Not_Zoidberg() Dim Inx As Long Dim i As Long Dim j As Long Dim x As Long Dim A1() As Variant Dim A2() As Variant Dim Rng1 As Range Application.ScreenUpdating = False A01 = Array(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, _ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 3, 3, 3, 3, 3, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, _ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 2, 2,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2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, _ 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, _ 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, _ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2) x = 0 For i = 1 To 24 'Rows For j = 1 To 64 'Columns ActiveSheet.Cells(i, j).Select With Selection .Value = A01(x) End With x = x + 1 Next j Next i x = 0 For i = 25 To 48 'Rows For j = 1 To 64 'Columns ActiveSheet.Cells(i, j).Select With Selection .Value = A02(x) End With x = x + 1 Next j Next i 'SET RANGE Set Rng1 = Range("A1:BN48") ActiveSheet.Range("A1").Select 'Add Colors For i = 1 To Rng1.Rows.Count For j = 1 To Rng1.Columns.Count Select Case Rng1.Cells(i, j).Value Case 3 Rng1.Cells(i, j).Interior.Color = RGB(253, 3, 74) Case 2 Rng1.Cells(i, j).Interior.Color = RGB(255, 255, 255) Case 1 Rng1.Cells(i, j).Interior.Color = RGB(1, 1, 1) Case 14 Rng1.Cells(i, j).Interior.Color = RGB(0, 153, 153) End Select 'For k = 1 To 10000: Next k, adds a delay to animate Next j Next i With Rng1 .ColumnWidth = 2 .RowHeight = 14.25 .ClearContents End With Application.ScreenUpdating = True End Sub
Your data is highly compressible, is a shame not to make use of it! Solving your question in a straight way, you may Split a long composed string: Dim sa As String sa = "2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2" sa = sa & " " & "2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 3" ' ' ... ' sa = sa & " " & "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2" a = Split(sa) Your array will be a string array, but arithmetic is not a problem in VBA. Alternativelly, you could pack your data (4 bit). Example: '0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 1 1 1 2 2 2 2 ... Array(&H01234567, &H89ABCDEF, &H11112222, ...) This way you could extract your data with little bit manipulation. But really think about compression!
I am going to offer a different approach to this problem. Create a text file with the values you want to set, arranged by rows and separated by commas (see .csv file format). For example use this pastebin file. Read the file row by row, parse each line into an array of strings, convert the strings into numbers and use the entire array to set the values of each row on the worksheet. Apply conditional formatting to the worksheet to display the correct colors based on the values For Example: Dim rng_1 As Range Set rng_1 = Range("M26") Dim fs As TextStream, txt_row As Variant Dim val_row() As Variant Dim n As Integer, i As Integer, j As Integer Set fs = fso.OpenTextFile("data.csv", ForReading, False) j = 0 While Not fs.AtEndOfStream ' Read a line of text and split into array of strings text_row = Strings.Split(fs.ReadLine, ",") 'Need to convert text values into numeric type n = UBound(text_row) + 1 ReDim val_row(0 To n - 1) For i = 1 To n val_row(i - 1) = Val(text_row(i - 1)) Next i ' Write values of entire row onto worksheet rng_1.Offset(j, 0).Resize(1, n).Value = val_row ' index the row j = j + 1 Wend fs.Close PS. There is rarely a case where .Select and Selection are needed. It is far easier and more robust to read/write directly from range references with the Range() object. In fact, avoid using .Cells() also and use named range references together with .Offset() and .Resize(). For example Dim A() as Variant A = Range("my_table").Resize(10,10).Value A(1,1) = 1 - A(1,2)*A(2,1) Range("my_table").Resize(10,10).Value = A
How do I put a specific integer into the middle of a sorted array in Swift?
I am writing code where five random numbers are given a value. Those five values are then sorted in an array in numerical order. However, when one value is equaled to 1, I want that number to be in the middle of the sorted array. When there is no number 1, the sorted array will work correctly. let fourthRandomNumber:Int = Int(arc4random_uniform(52)) let fifthRandomNumber:Int = Int(arc4random_uniform(52)) let sixthRandomNumber:Int = Int(arc4random_uniform(52)) let seventhRandomNumber:Int = Int(arc4random_uniform(52)) let eighthRandomNumber:Int = Int(arc4random_uniform(52)) var loFourthRandomNumberOutput: [Int] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 1, 1, 1, 1] var loFifthRandomNumberOutput: [Int] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 1, 1, 1, 1] var loSixthRandomNumberOutput: [Int] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 1, 1, 1, 1] var loSeventhRandomNumberOutput: [Int] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 1, 1, 1, 1] var loEighthRandomNumberOutput: [Int] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 1, 1, 1, 1] var hiFourthRandomNumberOutput: [Int] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11] var hiFifthRandomNumberOutput: [Int] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11] var hiSixthRandomNumberOutput: [Int] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11] var hiSeventhRandomNumberOutput: [Int] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11] var hiEighthRandomNumberOutput: [Int] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11] let loFourthRandomNumber:Int = loFourthRandomNumberOutput [fourthRandomNumber] let loFifthRandomNumber:Int = loFifthRandomNumberOutput [fifthRandomNumber] let loSixthRandomNumber:Int = loSixthRandomNumberOutput [sixthRandomNumber] let loSeventhRandomNumber:Int = loSeventhRandomNumberOutput [seventhRandomNumber] let loEighthRandomNumber:Int = loEighthRandomNumberOutput [eighthRandomNumber] let hiFourthRandomNumber:Int = hiFourthRandomNumberOutput [fourthRandomNumber] let hiFifthRandomNumber:Int = hiFifthRandomNumberOutput [fifthRandomNumber] let hiSixthRandomNumber:Int = hiSixthRandomNumberOutput [sixthRandomNumber] let hiSeventhRandomNumber:Int = hiSeventhRandomNumberOutput [seventhRandomNumber] let hiEighthRandomNumber:Int = hiEighthRandomNumberOutput [eighthRandomNumber] //NEED TO WORK OUT THIS ISSUE **(add ace)** var loDealerCardsArray = [loFourthRandomNumberOutput [fourthRandomNumber], loFifthRandomNumberOutput [fifthRandomNumber], loSixthRandomNumberOutput [sixthRandomNumber], loSeventhRandomNumberOutput [seventhRandomNumber], loEighthRandomNumberOutput [eighthRandomNumber]] //NEED TO WORK OUT THIS ISSUE **(add ace)** var hiDealerCardsArray = [hiFourthRandomNumberOutput [fourthRandomNumber], hiFifthRandomNumberOutput [fifthRandomNumber], hiSixthRandomNumberOutput [sixthRandomNumber], hiSeventhRandomNumberOutput [seventhRandomNumber], hiEighthRandomNumberOutput [eighthRandomNumber]] loDealerCardsArray.sort() loDealerCardsArray[0] loDealerCardsArray[1] loDealerCardsArray[2] print (loDealerCardsArray[0] + loDealerCardsArray[1] + loDealerCardsArray[2]) //NEED TO WORK OUT THIS ISSUE **(PULL IN RANDOM NUMBER FROM ARRAY SO THAT CARD APPEARS IN PROPER LOCATION when there is an ace hiDealerCardsArray.sort() hiDealerCardsArray[2] hiDealerCardsArray[3] hiDealerCardsArray[4] print (hiDealerCardsArray[2] + hiDealerCardsArray[3] + hiDealerCardsArray[4]) ////NEED TO WORK OUT THIS ISSUE **(PULL IN RANDOM NUMBER FROM ARRAY SO THAT CARD APPEARS IN PROPER LOCATION when there is an ace var DealerCardsArray = [fourthRandomNumber, fifthRandomNumber, sixthRandomNumber, seventhRandomNumber, eighthRandomNumber] DealerCardsArray.sort() DealerCardsArray[0] DealerCardsArray[1] DealerCardsArray[2] DealerCardsArray[3] DealerCardsArray[4] For example, five cards have a value of [0, 1, 2, 9, 10], and the array is sorted correctly. I am trying to sort the array so that the 1 is ALWAYS in the middle. When an ace (value of 1 or 11) appears in the sorted array I want it to look as follows: [0, 2, 1, 9, 10] Thank you in advance for your assistance
Something like: var cards = [0, 1, 2, 9, 10] // Get a list of all the aces in the array. let aces = cards.filter { $0 == 1 || $0 == 11 } // Now take the aces out of the array. cards = cards.filter { $0 != 1 && $0 != 11 } // Sort the array (unnecessary if its definitely already sorted). cards = cards.sort() // Re-insert the aces into the middle. aces.forEach { cards.insert($0, atIndex: cards.count/2) } // [0, 2, 1, 9, 10] Might do the trick (haha)!
var dealerCardsArray = [0, 1, 2, 9, 10] dealerCardsArray.sort() // Only if the value 1 exists in the array, remove it and add it back in the center position if let indexOfOne = dealerCardsArray.index(of: 1) { dealerCardsArray.remove(at: indexOfOne) dealerCardsArray.insert(1, at: array.count/2) } print(dealerCardsArray) // [0,2,1,9,10]
Replacing values in an object
I have an object that looks like this: {id: 1, cells: ["Ashar", 68345, 14, 66666, "Retail", 1, ""]} And I have an array of objects like so: [ {id: 1, cells: ["Ashar", 68345, 14, 46100, "Retail", 1, ""]}, {id: 2, cells: ["Ashar", 300881, 14, 37000, "Retail", 3, 3]}, {id: 3, cells: ["Rob", 94448, 17, 11395, "Retail", 1, ""]}, {id: 4, cells: ["Shahab", 19023870, 219, 12500, "Retail", 1, ""]}, {id: 5, cells: ["David", 29008000, 229, 12500, "Retail", 5, 26]} ] What I am trying to do is take the id of the first object and use it to search through the array to find the matching id and then replace the value of cells with the value from the first object. Any help with figuring this out would be much appreciated. Thanks for your time.
var temp = {id: 1, cells: ["Ashar", 68345, 14, 66666, "Retail", 1, ""]}; var arr=[ {id: 1, cells: ["Ashar", 68345, 14, 46100, "Retail", 1, ""]}, {id: 2, cells: ["Ashar", 300881, 14, 37000, "Retail", 3, 3]}, {id: 3, cells: ["Rob", 94448, 17, 11395, "Retail", 1, ""]}, {id: 4, cells: ["Shahab", 19023870, 219, 12500, "Retail", 1, ""]}, {id: 5, cells: ["David", 29008000, 229, 12500, "Retail", 5, 26]} ]; arr.forEach(function(value,key){ if(value.id == temp.id) { value.cells=temp.cells; } });