Skip to content

Instantly share code, notes, and snippets.

View danielchikaka's full-sized avatar

Daniel Chikaka danielchikaka

View GitHub Profile
@danielchikaka
danielchikaka / remove_minimum.py
Created April 20, 2022 08:18
Given an array of integers, remove the smallest value. Do not mutate the original array/list. If there are multiple elements with the same value, remove the one with a lower index. If you get an empty array/list, return an empty array/list. Don't change the order of the elements that are left.
# def remove_smallest(numbers):
# arr = numbers[:]
# if len(arr) > 0:
# arr.pop(arr.index(min(arr)))
# return arr
# else:
# return []
def remove_smallest(numbers):
a = numbers[:]
@danielchikaka
danielchikaka / find_next_square.py
Last active April 20, 2022 06:23
Complete the findNextSquare method that finds the next integral perfect square after the one passed as a parameter. Recall that an integral perfect square is an integer n such that sqrt(n) is also an integer. If the parameter is itself not a perfect square then -1 should be returned. You may assume the parameter is non-negative.
# import math
# def find_next_square(sq):
# # Return the next square if sq is a square, -1 otherwise
# if sq % math.sqrt(sq) == 0:
# sq_number = math.sqrt(sq)
# new_sq_sq = (sq_number + 1)**2
# if new_sq_sq % math.sqrt(new_sq_sq) == 0:
# return new_sq_sq
# else:
# return -1
@danielchikaka
danielchikaka / uppercaseArray.js
Created December 10, 2021 15:29
Function to capitalize string array
const changeToUpperCase = arr => {
const newArr = []
for (const element of arr) {
newArr.push(element.toUpperCase())
}
return newArr
}
const countries = ['Finland', 'Sweden', 'Norway', 'Denmark', 'Iceland']
console.log(changeToUpperCase(countries))
@danielchikaka
danielchikaka / unlimitedSum.js
Created December 10, 2021 15:24
Unlimited number of parameters summation
// function declaration
const sumAllNums = (...args) => {
let sum = 0
for (const element of args) {
sum += element
}
return sum
}
@danielchikaka
danielchikaka / maximumNumber.js
Last active December 10, 2021 11:12
Finding the maximum number in array
let arr = [6, 89, 3, 45];
let maximus = Math.max.apply(null, arr);
// Oh, even better
let maximus = Math.max(...arr)
function findVowelsConsonants(sentence) {
var arr = [];
var arrSentence = sentence.split('');
// Get all vowels
arrSentence.forEach(el => {
if(['a','e', 'i', 'o', 'u'].indexOf(el.toLowerCase()) !== -1){
arr.push(el);
}
} );
// Get all consonants
@danielchikaka
danielchikaka / app.js
Created August 28, 2018 15:16 — forked from sogko/app.js
gulp + expressjs + nodemon + browser-sync
'use strict';
// simple express server
var express = require('express');
var app = express();
var router = express.Router();
app.use(express.static('public'));
app.get('/', function(req, res) {
res.sendfile('./public/index.html');
var defaults = {
number: 1,
bool: true,
magic: 'real',
animal: 'whale',
croutons: 'delicious'
};
var options = {
number: 2,
@danielchikaka
danielchikaka / jsbin.gewozekoxi.js
Last active January 17, 2018 08:47
Getting Date and Time source https://jsbin.com/gewozekoxi
function todayDate(){
var day;
switch(new Date().getDay()){
case 0:
day = "Sunday";
break;
case 1:
day = "Monday";
break;
case 2:
@danielchikaka
danielchikaka / global-variables-are-bad.js
Created August 2, 2017 05:18 — forked from hallettj/global-variables-are-bad.js
How and why to avoid global variables in JavaScript
// It is important to declare your variables.
(function() {
var foo = 'Hello, world!';
print(foo); //=> Hello, world!
})();
// Because if you don't, the become global variables.
(function() {