This file contains hidden or 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
| 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; |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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; | |
| } |
This file contains hidden or 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
| function slasher(arr, howMany) { | |
| // it doesn't always pay to be first | |
| arr = arr.slice(howMany); | |
| return arr; | |
| } |
This file contains hidden or 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
| 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) + "..."; |
This file contains hidden or 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
| 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++) { | |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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 { |
NewerOlder