Instantly share code, notes, and snippets.

# Daniel Chikaka danielchikaka

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.
This file contains 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
 # 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[:]
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.
This file contains 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
 # 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
Created December 10, 2021 15:29
Function to capitalize string array
This file contains 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
 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))
Created December 10, 2021 15:24
Unlimited number of parameters summation
This file contains 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 declaration ​ const sumAllNums = (...args) => { let sum = 0 for (const element of args) { sum += element } return sum }
Last active December 10, 2021 11:12
Finding the maximum number in array
This file contains 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
 let arr = [6, 89, 3, 45]; let maximus = Math.max.apply(null, arr); // Oh, even better let maximus = Math.max(...arr)
Created September 9, 2021 07:25
This file contains 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 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
Created August 28, 2018 15:16 — forked from sogko/app.js
gulp + expressjs + nodemon + browser-sync
This file contains 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
 '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');
Created January 22, 2018 15:45 — forked from pbojinov/example.js
A vanilla JS extend() function - http://gomakethings.com/vanilla-javascript-version-of-jquery-extend/
This file contains 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 defaults = { number: 1, bool: true, magic: 'real', animal: 'whale', croutons: 'delicious' }; var options = { number: 2,
Last active January 17, 2018 08:47
Getting Date and Time source https://jsbin.com/gewozekoxi
This file contains 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 todayDate(){ var day; switch(new Date().getDay()){ case 0: day = "Sunday"; break; case 1: day = "Monday"; break; case 2:
Created August 2, 2017 05:18 — forked from hallettj/global-variables-are-bad.js
How and why to avoid global variables in JavaScript
This file contains 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
 // 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() {