Skip to content

Instantly share code, notes, and snippets.

View Hoxtygen's full-sized avatar
🎯
Focusing

Wasiu Idowu Hoxtygen

🎯
Focusing
  • Nigeria
View GitHub Profile
@Hoxtygen
Hoxtygen / sorting
Created November 24, 2016 23:33
How sorting works
var myLove = ["the", "name", "of", "my", "love", "is", "yet", "unknown"];
var Array = [1, 7, 10, 40, 55, 16, 37, 85, 90, 100];
// This sort gives the default sorting
var newLove = myLove.sort();
// this sort gives a sorting whereby the first number comes first
var newArray = Array.sort(function(a, b) {
return a-b;
// however, if you want the largest number to come first then do b-a
@Hoxtygen
Hoxtygen / palindrome
Last active November 27, 2016 20:55
This is a solution to the FCC bonfire palindrome challenge
function palindrome (str) {
str = str.replace(/\W|_/g, "").toLowerCase();
str = str.split(" ").join(" ");
var NewStr = str.split("").reverse().join("");
if (str === NewStr) {
return true;
} else {
@Hoxtygen
Hoxtygen / Return Largest Numbers in Arrays
Created November 30, 2016 21:00
A solution to FCC challenge
function largestOfFour(arr) {
// You can do this!
var result = [];
for (var i = 0; i < arr.length; i++) {
var largest = 0;
for (var j = 0; j < arr[i].length; j++) {
function truncateString(str, num) {
// Clear out that junk in your trunk
if (str.length > num) {
if (num <= 3) {
str= str.slice(0, num) + "...";
} else {
str = str.slice(0, num-3) + "...";
function slasher(arr, howMany) {
// it doesn't always pay to be first
arr = arr.slice(howMany);
return arr;
}
function bouncer(arr) {
// Don't show a false ID to this bouncer.
var filtered = [];
filtered = arr.filter(function (x) {
return x !==undefined && x !==null & x!==false && x === NaN && x !==0 && x !== "";
});
return filtered;
}
function destroyer(arr) {
//create a temporary array that includes both the arrays and the arguments, giving a multidimensional array.
var args = Array.prototype.slice.call(arguments);
//cut out the original array by splicing it out leaving only the arguments
args.splice(0,1);
//create an empty array that will contain the result after the array and arguments have been compared
var newArr= [];
//iterate through the original array
for (var i = 0; i < arr.length; i++) {
//iterate through the arguments array
function getIndexToIns(arr, num) {
//Add the value of num to the array
arr.push(num);
//Sort the array
arr.sort(function(a, b) {
return a-b;
});
//Get the index of value num
arr = arr.indexOf(num);
return arr;
@Hoxtygen
Hoxtygen / forismatic
Created December 30, 2016 18:30
how to implement forismatic api
$(document).ready(function() {
var quote;
var author;
function getNewQuote() {
$.ajax({
url: "http://api.forismatic.com/api/1.0/",
@Hoxtygen
Hoxtygen / Diff 2 Arrays
Created April 21, 2017 23:18
FCC Intermediate Algorithm Scripting
function diffArray(arr1, arr2) {
//create a placeholder array that will contain the resultant values
var newArray = [];
//iterate through arr1
for (var i = 0; i < arr1.length; i++) {
//if arr2 doesn't contain items in arr1
if (arr2.indexOf(arr1[i]) === -1) {
//save it in newArray
newArray.push(arr1[i]);
}