Bootstrap List Grid View
A Pen by Ajay Patel on CodePen.
// O(nlogn) | |
// Merge two sorted arrays | |
const merge = (arr1, arr2) => { | |
const sorted = []; | |
let i = 0; | |
let j = 0; | |
// Loop through both arrays and push the greater elements by | |
while(i < arr1.length && j < arr2.length) { | |
if(arr2[j] > arr1[i]) { |
/** | |
* Insertion sort. | |
* O(n^2) | |
*/ | |
const insertionSort = (arr) => { | |
for(let i = 1; i < arr.length; i++) { | |
let j = i; | |
// const prev = arr[j-1]; | |
// const next = arr[j]; | |
// console.log(prev, next) |
/** | |
* My JS Implementation of Bubble Sort. | |
*/ | |
const bubbleSort = arr => { | |
let noSwaps; | |
/** | |
* Swap element in an arr for another | |
*/ | |
const swap = (arr, index1, index2) => { |
Bootstrap List Grid View
A Pen by Ajay Patel on CodePen.
<div id="app"></div> |
# -*- coding: utf-8 -*- | |
""" | |
One of the simplest and most widely known ciphers is a Caesar cipher, also known as a shift cipher. | |
In a shift cipher the meanings of the letters are shifted by some set amount. | |
A common modern use is the ROT13 cipher, where the values of the letters are shifted by 13 places. | |
Thus 'A' ↔ 'N', 'B' ↔ 'O' and so on. | |
Write a function which takes a ROT13 encoded string as input and returns a decoded string. |
""" | |
Return the lowest index at which a value (second argument) | |
should be inserted into an array (first argument) once it has been sorted. | |
The returned value should be a number. | |
For example, getIndexToIns([1,2,3,4], 1.5) should return 1 | |
because it is greater than 1 (index 0), but less than 2 (index 1). | |
Likewise, getIndexToIns([20,3,5], 19) should return 2 | |
because once the array has been sorted it will look like [3,5,20] |
""" | |
You will be provided with an initial array (the first argument), | |
followed by one or more arguments. | |
Remove all elements from the initial array that are of the same value as these arguments. | |
""" | |
def destroyer(*args): | |
the_list = args[0] | |
to_remove = list(args[1:]) | |
# Doing some list comprehension | |
return [element for element in the_list if element not in to_remove] |
""" | |
null in js, None in python | |
false is False | |
Remove all falsy values from an array. | |
Falsy values in JavaScript are false, null, 0, "", undefined, and NaN | |
I had to modify some stuff from this challenge due to some differences | |
in Javascript and Python | |
""" |
""" | |
Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array. | |
For example, ["hello", "Hello"], should return true because all of the letters in the second string are present in the first, ignoring case. | |
The arguments ["hello", "hey"] should return false because the string "hello" does not contain a "y". | |
Lastly, ["Alien", "line"], should return true because all of the letters in "line" are present in "Alien". | |
""" | |
def mutation(the_list): |