# Code Samples

Here is a collection of commonly asked coding questions. Each question has an explanation of how to perform the operation specified as well as a working code sample that can copied. These examples aim to provide the most pragmatic and succinct code that optimizes efficiency and readability. We'll be constantly adding examples and if you have questions or requests, contact us on FB or TW.

How to sort an array of objects by object property in Javascript

The standard way to sort an array of objects is to use the sort method and specify a custom compare function. The compare function can then be used to specify custom code that will be used when comparing objects to determine the order. The compare function takes two parameters a and b. a and b represent the first and second element to be compared. The compare function should return an integer and if the integer is > 0 then a should be sorted after b. If the integer returned is < 0 then a should be sorted before b. And finally if 0 is returned then a and b are equivalent and can stay in their original order.

Read more >

How to remove an item from a list in Python

The standard way to remove an item from a list is to use remove by specifying the item you want removed. This will remove the first occurrence of the item specified in the list. One thing to note is that if the item specified does not exist, a ValueError will be raised. You can also use del to remove an item from the list by specifying the index.

Read more >

How to insert an item into a list in Python

There are multiple ways to insert an item into a list in Python depending on your use-case. The first is append which will add the item to the end of the list. There's also insert to add the item at an arbitrary index. And if you need to add a list of items to a list, you can use extend. And in addition to extend, you can also use + to concatenate multiple lists together.

Read more >

How to insert an item into an array in Javascript

The standard way to insert an item into an array is to use splice and provide the item your want to insert as the third argument. The first argument is the specific index where you want to insert the item and the second argument should be set to 0 since we're not removing anything from the array.

Read more >

Getting started with ChatGPT in Python

OpenAI has made it really easy to get started using ChatGPT and provides documentation and libraries for a wide variety of languages (Python, Javacript, C#/.NET, Crystal, Go, Java, Kotlin, PHP, R, Ruby, Scala, Swift, Unity, Unreal Engine). You'll need to signup for an account and then create an API key. Once you have an API key, you can start making requests to ChatGPT and then the possibilities are limitless as far as what you can do with it.

Read more >

Getting started with ChatGPT in Javascript

OpenAI has made it really easy to get started using ChatGPT and provides documentation and libraries for a wide variety of languages (Python, Javacript, C#/.NET, Crystal, Go, Java, Kotlin, PHP, R, Ruby, Scala, Swift, Unity, Unreal Engine). You'll need to signup for an account and then create an API key. Once you have an API key, you can start making requests to ChatGPT and then the possibilities are limitless as far as what you can do with it.

Read more >

How to generate a random number/string in Python

The standard way to generate a random number is to use the random module. The random() function will return a floating point number from 0 to 1 (but not including 1). In addition, there's also a choice() function that will randomly select an item from a list. choice() can be used to select from a pre-specified list of characters or numbers.

Read more >

Join our community

Your sign-up could not be saved. Please try again.
Your sign-up was successful.

Sign-up and get tips to becoming a software engineer.