Golang prepend the array [duplicate]












0
















This question already has an answer here:




  • golang prepend a string to a slice …interface{}

    1 answer




package main

import (
"fmt"
)

func main() {

var result int
var tempArr int
tempArr = append(tempArr, 1, 2, 3, 5)
result = append(result, tempArr)
prepend := int{1, 2, 3}
result = append(int{prepend}, result...) // Not working
fmt.Println(result)
}


What is the correct way to prepend to an array? I need help to fix this line:



result = append(int{prepend}, result...)









share|improve this question















marked as duplicate by Volker go
Users with the  go badge can single-handedly close go questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 15 '18 at 6:56


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    Following push front in the slice tricks wiki, the code should be: result = append(int{prepend}, result...)

    – ThunderCat
    Nov 15 '18 at 1:01













  • I got this working by doing this result = append(int{prepend}, result...)

    – Jackal
    Nov 15 '18 at 1:11
















0
















This question already has an answer here:




  • golang prepend a string to a slice …interface{}

    1 answer




package main

import (
"fmt"
)

func main() {

var result int
var tempArr int
tempArr = append(tempArr, 1, 2, 3, 5)
result = append(result, tempArr)
prepend := int{1, 2, 3}
result = append(int{prepend}, result...) // Not working
fmt.Println(result)
}


What is the correct way to prepend to an array? I need help to fix this line:



result = append(int{prepend}, result...)









share|improve this question















marked as duplicate by Volker go
Users with the  go badge can single-handedly close go questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 15 '18 at 6:56


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    Following push front in the slice tricks wiki, the code should be: result = append(int{prepend}, result...)

    – ThunderCat
    Nov 15 '18 at 1:01













  • I got this working by doing this result = append(int{prepend}, result...)

    – Jackal
    Nov 15 '18 at 1:11














0












0








0









This question already has an answer here:




  • golang prepend a string to a slice …interface{}

    1 answer




package main

import (
"fmt"
)

func main() {

var result int
var tempArr int
tempArr = append(tempArr, 1, 2, 3, 5)
result = append(result, tempArr)
prepend := int{1, 2, 3}
result = append(int{prepend}, result...) // Not working
fmt.Println(result)
}


What is the correct way to prepend to an array? I need help to fix this line:



result = append(int{prepend}, result...)









share|improve this question

















This question already has an answer here:




  • golang prepend a string to a slice …interface{}

    1 answer




package main

import (
"fmt"
)

func main() {

var result int
var tempArr int
tempArr = append(tempArr, 1, 2, 3, 5)
result = append(result, tempArr)
prepend := int{1, 2, 3}
result = append(int{prepend}, result...) // Not working
fmt.Println(result)
}


What is the correct way to prepend to an array? I need help to fix this line:



result = append(int{prepend}, result...)




This question already has an answer here:




  • golang prepend a string to a slice …interface{}

    1 answer








go






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 0:50









Marco Bonelli

23.4k116373




23.4k116373










asked Nov 15 '18 at 0:43









JackalJackal

1,45011924




1,45011924




marked as duplicate by Volker go
Users with the  go badge can single-handedly close go questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 15 '18 at 6:56


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Volker go
Users with the  go badge can single-handedly close go questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 15 '18 at 6:56


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1





    Following push front in the slice tricks wiki, the code should be: result = append(int{prepend}, result...)

    – ThunderCat
    Nov 15 '18 at 1:01













  • I got this working by doing this result = append(int{prepend}, result...)

    – Jackal
    Nov 15 '18 at 1:11














  • 1





    Following push front in the slice tricks wiki, the code should be: result = append(int{prepend}, result...)

    – ThunderCat
    Nov 15 '18 at 1:01













  • I got this working by doing this result = append(int{prepend}, result...)

    – Jackal
    Nov 15 '18 at 1:11








1




1





Following push front in the slice tricks wiki, the code should be: result = append(int{prepend}, result...)

– ThunderCat
Nov 15 '18 at 1:01







Following push front in the slice tricks wiki, the code should be: result = append(int{prepend}, result...)

– ThunderCat
Nov 15 '18 at 1:01















I got this working by doing this result = append(int{prepend}, result...)

– Jackal
Nov 15 '18 at 1:11





I got this working by doing this result = append(int{prepend}, result...)

– Jackal
Nov 15 '18 at 1:11












1 Answer
1






active

oldest

votes


















2














The type is mismatch. int{prepend} type is int. But prepend type is int. So int{prepend} is not correct. The right way is int{prepend}, below code will pass.



result = append(int{prepend}, result...)


The result will be:



[[1 2 3] [1 2 3 5]]





share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    The type is mismatch. int{prepend} type is int. But prepend type is int. So int{prepend} is not correct. The right way is int{prepend}, below code will pass.



    result = append(int{prepend}, result...)


    The result will be:



    [[1 2 3] [1 2 3 5]]





    share|improve this answer




























      2














      The type is mismatch. int{prepend} type is int. But prepend type is int. So int{prepend} is not correct. The right way is int{prepend}, below code will pass.



      result = append(int{prepend}, result...)


      The result will be:



      [[1 2 3] [1 2 3 5]]





      share|improve this answer


























        2












        2








        2







        The type is mismatch. int{prepend} type is int. But prepend type is int. So int{prepend} is not correct. The right way is int{prepend}, below code will pass.



        result = append(int{prepend}, result...)


        The result will be:



        [[1 2 3] [1 2 3 5]]





        share|improve this answer













        The type is mismatch. int{prepend} type is int. But prepend type is int. So int{prepend} is not correct. The right way is int{prepend}, below code will pass.



        result = append(int{prepend}, result...)


        The result will be:



        [[1 2 3] [1 2 3 5]]






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 4:29









        James ShiJames Shi

        64369




        64369

















            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine