Skip to content

Instantly share code, notes, and snippets.

View khalid32's full-sized avatar
🤩
enthusiastic

Khalid Syfullah Zaman khalid32

🤩
enthusiastic
View GitHub Profile
/*
Design a cash register drawer function checkCashRegister() that accepts purchase price as the first argument (price), payment as the second argument (cash), and cash-in-drawer (cid) as the third argument.
cid is a 2D array listing available currency.
Return the string "Insufficient Funds" if cash-in-drawer is less than the change due. Return the string "Closed" if cash-in-drawer is equal to the change due.
Otherwise, return change in coin and bills, sorted in highest to lowest order.
*/
@khalid32
khalid32 / Inventory Update
Created May 31, 2017 04:29
Freecodecamp's Advanced Algorithm Scripting Challenge
/*
Compare and update the inventory stored in a 2D array against a second 2D array of a fresh delivery. Update the current existing inventory item quantities (in arr1). If an item cannot be found, add the new item and quantity into the inventory array. The returned inventory array should be in alphabetical order by item.
*/
function updateInventory(arr1, arr2) {
// All inventory must be accounted for or you're fired!
var inventory = arr1.concat(arr2).reduce(function(acc, next){
if(acc[next[1]]){
acc[next[1]] += next[0];
}else{
@khalid32
khalid32 / No repeats please
Created May 31, 2017 06:05
Freecodecamp's Advanced Algorithm Scripting Challenge
/*
Return the number of total permutations of the provided string that don't have repeated consecutive letters. Assume that all characters in the provided string are each unique.
For example, aab should return 2 because it has 6 total permutations (aab, aab, aba, aba, baa, baa), but only 2 of them (aba and aba) don't have the same letter (in this case a) repeating.
*/
function permAlone(str) {
var regex = /(.)\1+/g;
var arr = str.split(''), permutations = [], temp;
@khalid32
khalid32 / 'Make a Person'
Last active June 1, 2017 03:58
Freecodecamp's Advanced Algorithm Scripting Challenge
var Person = function(firstAndLast) {
// Complete the method below and implement the others similarly
this.first = firstAndLast.split(' ')[0];
this.last = firstAndLast.split(' ')[1];
this.getFirstName = function(){
return this.first;
};
this.getLastName = function(){
@khalid32
khalid32 / 'Map the Debris' using forEach()
Created June 1, 2017 04:42
Freecodecamp's Advanced Algorithm Scripting Challenge
function orbitalPeriod(arr) {
var GM = 398600.4418;
var earthRadius = 6367.4447;
arr.forEach(function(obj){
var orbPeriod = Math.round(2*Math.PI*Math.sqrt(Math.pow(earthRadius + obj.avgAlt, 3)/GM));
obj.orbitalPeriod = orbPeriod;
delete obj.avgAlt;
});
@khalid32
khalid32 / PairWise
Created June 1, 2017 04:58
Freecodecamp's Advanced Algorithm Scripting Challenge
/*
Given an array arr, find element pairs whose sum equal the second argument arg and return the sum of their indices.
If multiple pairs are possible that have the same numeric elements but different indices, return the smallest sum of indices. Once an element has been used, it cannot be reused to pair with another.
For example pairwise([7, 9, 11, 13, 15], 20) returns 6. The pairs that sum to 20 are [7, 13] and [9, 11]. We can then write out the array with their indices and values.
Index 0 1 2 3 4
Value 7 9 11 13 15
Below we'll take their corresponding indices and add them.
@khalid32
khalid32 / Gradle Deamon
Created June 8, 2017 07:13
Consider using the Gradle Daemon for faster build in react native; add the syntax to gradle.properties
android.useDeprecatedNdk=true
org.gradle.daemon=true
org.gradle.jvmargs=-Xmx1536M
@khalid32
khalid32 / Network Command Line
Created June 11, 2017 14:29
Helps to restart wifi/network connection...
sudo service network-manager restart
@khalid32
khalid32 / How to init a specific version of react-native
Last active June 15, 2017 12:28
with every new release of React Native, more and more plugins become incompatible and are largely not supported by their authors. So the only option is to continue using previous versions that work with the plugins. All you need to do is to write it on existing project and you are good to go, no double installation.
- npm i -S react-native@version
//such as, @0.43.3
//and then
- react-native upgrade
//Alternate Solution
//install rninit
sudo npm install -g rninit
//then react-native project
rninit init [Project_Name] --source react-native@version
@khalid32
khalid32 / build.gradle
Created June 15, 2017 09:48
it will be useful if someone's working on react-native-google-signin, background-geolocation, react-native-maps and lottie..
apply plugin: "com.android.application"
import com.android.build.OutputFile
/**
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
* and bundleReleaseJsAndAssets).
* These basically call `react-native bundle` with the correct arguments during the Android build
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
* bundle directly from the development server. Below you can see all the possible configurations