This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Mapping over a 2D array in JS. | |
Taken from: https://stackoverflow.com/questions/45659734/how-to-use-array-map-with-a-2-dimensional-array | |
*/ | |
arr.map( function( row ) { | |
return row.map( function( cell ) { | |
return foo( cell ); | |
} ); | |
} ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Fill/initialize a 2D JS array | |
//From: https://www.quora.com/In-JavaScript-how-do-you-create-an-empty-2D-array | |
var twoDArray = Array(2).fill(null).map(()=>Array(2).fill(null)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Iterative Solution | |
var bsearchIter = function(nums, target) { | |
let [left, right] = [0, nums.length-1]; | |
while(left <= right) { | |
let mid = Math.floor((left + right)/2); | |
if(target < nums[mid]) { | |
right = mid-1; | |
} else if(target > nums[mid]){ | |
left = mid+1; | |
}else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Get the column of a 2D array in JS | |
//Taken from https://stackoverflow.com/questions/7848004/get-column-from-a-two-dimensional-array | |
const arrayColumn = (arr, n) => arr.map(x => x[n]); | |
const twoDimensionalArray = [ | |
[1, 2, 3], | |
[4, 5, 6], | |
[7, 8, 9], | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Heap implementation in JS. | |
Description of Heap: | |
https://en.wikipedia.org/wiki/Heap_(data_structure) | |
Defaults to MinHeap. Extend class and override | |
compare(a, b) to implement MaxHeap. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Trie.js - super simple JS implementation | |
// https://en.wikipedia.org/wiki/Trie | |
// ----------------------------------------- | |
// we start with the TrieNode | |
function TrieNode(key) { | |
// the "key" value will be the character in sequence | |
this.key = key; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Sequential Member Numbers | |
* Member numbers are automatically increased from the value set for $starting_member_number after each member registration | |
* Existing members already in the system will not receive a membership number | |
*/ | |
//Generate member_number when a user is registered. | |
function generate_member_number($user_id) | |
{ | |
$starting_member_number = 100000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Sequential Member Numbers | |
* Member numbers are automatically increased from the value set for $starting_member_number after each member registration | |
* Existing members already in the system will not receive a membership number | |
*/ | |
//Generate member_number when a user is registered. | |
function generate_member_number($user_id, $decrement = false) | |
{ | |
$starting_member_number = 100000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Set flag to hide members from the directory upon new user creation by an admin*/ | |
function pmpromd_set_visibility_to_hidden_edit_user_created_user ($user_id, $notify) | |
{ | |
update_user_meta( $user_id, 'pmpromd_hide_directory', true ); | |
} | |
add_action('edit_user_created_user', 'pmpromd_set_visibility_to_hidden_edit_user_created_user', 10, 2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Originally coded by user Marc1205 in private support forum: | |
// https://www.paidmembershipspro.com/forums/topic/different-stylesheets-for-user-levels/ | |
function pmproc_preheader() { | |
if(pmpro_hasMembershipLevel('your_membership_name')) { | |
wp_enqueue_style( 'basse', get_stylesheet_directory_uri().'/mfk-dev/assets/css/basse.css' ); | |
} | |
if(pmpro_hasMembershipLevel('your_membership_name')) { |