Golang prepend the array [duplicate]
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...)
go
marked as duplicate by Volker
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.
add a comment |
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...)
go
marked as duplicate by Volker
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 thisresult = append(int{prepend}, result...)
– Jackal
Nov 15 '18 at 1:11
add a comment |
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...)
go
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
go
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
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
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 thisresult = append(int{prepend}, result...)
– Jackal
Nov 15 '18 at 1:11
add a comment |
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 thisresult = 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
add a comment |
1 Answer
1
active
oldest
votes
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]]
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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]]
add a comment |
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]]
add a comment |
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]]
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]]
answered Nov 15 '18 at 4:29
James ShiJames Shi
64369
64369
add a comment |
add a comment |
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