Skip to content

Instantly share code, notes, and snippets.

AWSTemplateFormatVersion: 2010-09-09
Parameters:
EC2InstanceType:
Type: String
EC2AMI:
Type: 'AWS::EC2::Image::Id'
Default: 'ami-03d8261f577d71b6a'
def multi_imperative(n = 12):
if(n > 12):
return print('maximum number allowed is 12')
for i in range(1,n+1):
s = ''
for j in range(1,n+1):
s += '{0:4} '.format(i*j)
print(s)
if (Array.isArray(req.files.picture)) {
if (req.files.picture.length > 6)
return res.status(400).json({
status: 400,
message: `You can't upload more than 6 images at once`
});
for (let picture of req.files.picture) {
if (!picture.mimetype.includes('image/'))
return res.status(400).json({
@dre4success
dre4success / mergeSort.js
Created September 19, 2018 15:37
A merge sort algorithm
// a function that takes two arrays and merge them
function merge(arr1, arr2){
let i = 0
let j = 0
let results = []
while (i < arr1.length && j < arr2.length) {
if(arr2[j] > arr1[i]) {
results.push(arr1[i])
i++
@dre4success
dre4success / anagram.js
Created September 12, 2018 09:44
Giving two strings, it should return true if it's an anagram i.e a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once
function anagram (str1, str2) {
if (str1.length !== str2.length) return false
let frequencyCounter = {}
for (let val of str1) {
// increment occurence of val in frequencyCounter
frequencyCounter[val] = (frequencyCounter[val] || 0) + 1
}
for (let val of str2) {
if(!frequencyCounter[val]) {
return false
@dre4success
dre4success / cloudSettings
Last active July 22, 2019 17:21
Given an unsorted array of n elements, find if the element k is present in the given array or not. return 'YES' or 'NO'
{"lastUpload":"2019-07-22T17:21:44.605Z","extensionVersion":"v3.4.1"}
@dre4success
dre4success / isPalindrome.js
Created October 4, 2017 07:19
To return true or false if a statement is palindrome, i.e same when spelt backward
function isPalindrome(str) {
// convert string to lowercase
str = str.toLowerCase();
// convert string to an array
let strArr = str.split('');
// what it will be checked against to eliminitate non alphabetic characters
let AlphabetArr = 'abcdefghijklmnopqrstuvwxyz'.split('');
// initialize an empty array
let newContainer = []
@dre4success
dre4success / fizz-buzz.js
Created October 3, 2017 19:25
number divisible by 3 outputs fizz, by 5 outputs buzz, but both outputs fizzbuzz
const fizzBuzz = (num = 20) => {
for(let i = 1; i <= num; i++) {
if(i % 15 === 0) console.log('FizzBuzz');
else if(i % 3 === 0) console.log('Fizz');
else if(i % 5 === 0) console.log('Buzz');
else console.log(i)
}
}
fizzBuzz()
@dre4success
dre4success / reverse.js
Created October 2, 2017 20:41
Three ways or reversing a string
// reversing a string with a decrementing forloop
function reverse(str) {
let st = "";
for(let i = str.length - 1; i >= 0; i--) {
st += str[i]
}
return st
}
// through a recursion
@dre4success
dre4success / Cassidy-Williams.js
Last active September 25, 2017 22:22
Write a function duplicate that takes in an array arr and an int n, and returns an array that duplicates arr n times
// with loop
function duplicate (arr, n) {
let arry = [];
for(let i = 0; i < n; i++) {
arry = [...arry, ...arr]
}
return arry
}