Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View Hoxtygen's full-sized avatar
🎯
Focusing

Wasiu Idowu Hoxtygen

🎯
Focusing
  • Nigeria
View GitHub Profile
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;
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 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 slasher(arr, howMany) {
// it doesn't always pay to be first
arr = arr.slice(howMany);
return arr;
}
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) + "...";
@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++) {
@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 {