Convert from JavaScript to Go-ThrowExceptions

Exception or error:

I know nothing about JavaScript.

Assume that v contains a list of positive integers, vi is an index value, say current vi = 0.

I would like to know how to convert v.splice(vi, 1) to Golang

Is .splice() is equivalent to slices?

How to solve:

v.splice(vi, 1) removes 1 element from vi. To do the same in go, you can do:

append(v[:vi],v[vi+1:]...)

That is, first get the slice up to vi, then add all the elements after vi.

Answer´╝Ü

From : https://www.w3schools.com/jsref/jsref_splice.asp

Syntax
array.splice(index, howmany, item1, ….., itemX)

Parameter: index
Description. An integer that specifies at what position to add/remove items, Use negative values to specify the position from the end of the array.

Parameter :howmany(Optional)
Description: The number of items to be removed. If set to 0, no items will be removed

Parameter:item1, …, itemX (Optional)
Description: The new item(s) to be added to the array

You may visit https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_splice for trying it yourself

Leave a Reply

Your email address will not be published. Required fields are marked *