Skip to content

Instantly share code, notes, and snippets.

<b>asda</b>
function promiseAll(arr) {
// fill this in
}
promiseAll([Promise.resolve(1), Promise.resolve(4)]).then(resp => {
console.log(resp)
})
@alnorris
alnorris / mergeSorted.js
Created May 10, 2016 19:49
Merge 2 sorted arrays
var arr1 = [3,5,8,10,15,18];
var arr2 = [6,10,15,20,25];
function sort(arr1, arr2) {
var sortedArr = [];
var x = y = 0;
while(x < arr1.length && y < arr2.length) {
if(arr1[x] < arr2[y]) {
sortedArr.push(arr1[x++]);
@alnorris
alnorris / centermiddlediv.css
Created September 6, 2015 20:05
Center middle a Div
/*
When changing the width and height, change the margin to a negative half sized value, and line height
/*
#centermiddle {
margin: -100px 0 0 -100px;
display: block;
border:1px solid red;
width: 200px ;
height: 200px;
<?php
$msg = "Hello World!";
for($i = 0; $i < (strlen($msg)-1)/2; $i++) {
$temp = $msg[$i];
$msg[$i] = $msg[strlen($msg)-1-$i];
$msg[strlen($msg)-1-$i] = $temp;
}
var arr = [4,8,2,4,10,2,4];
for(var i = 0; i < arr.length; i++) {
for(var z = 0; z < arr.length-i; z++) {
if(arr[z] > arr[z+1]) {
//swap
var temp = arr[z];
arr[z] = arr[z+1]
arr[z+1] = temp;
@alnorris
alnorris / poweroftwo.php
Created March 16, 2015 17:17
Power of Two in PHP
<?php
$result = 1;
while($result <= 1024){
print $result . "\n";
$result = $result << 1;
}
@alnorris
alnorris / linkedlist.php
Created March 16, 2015 17:05
Linked List in PHP
<?php
class node {
public $data;
public $nextNode;
public function __construct($data, $nextNode) {
$this->data = $data;
@alnorris
alnorris / gist:6710436
Last active December 23, 2015 23:29
Linked list in Javascript
function node(data, next) {
this.data = data;
this.next = next;
}
function linkedlist() {
this.first = null;
}
linkedlist.prototype.insertNode = function(data) {
@alnorris
alnorris / mergesort.php
Created September 14, 2013 17:17
Implementation of merge-sort in PHP.
<?php
// declare example array to be sorted
$arr1 = array(4,16,32,33,49,3,2,7,4,88);
// sort array and print
print_r(mergeRec($arr1));
// Recrusive mergesort function