Skip to content

Instantly share code, notes, and snippets.

View Smakar20's full-sized avatar

Sohini Makar Smakar20

  • Rally Health Inc
  • San Francisco
View GitHub Profile
@Smakar20
Smakar20 / JsoE-0.js
Created August 1, 2017 21:39
null created by smakar20 - https://repl.it/JsoE/0
/*Given an array of numbers, replace each number with the product of all the numbers in the array except the number itself *without* using division.*/
//method 1
/*(function(inp){
if(inp.length <= 0) return "not a valid input"
let out = []
for(var i = 0; i < inp.length; i++){
let prod1 = 1;
let prod2 = 1;
for(var j = 0; j < i; j++){
@Smakar20
Smakar20 / KoQp-0.js
Created September 7, 2017 18:21
null created by smakar20 - https://repl.it/KoQp/0
/*Have the function RemoveBrackets(str) take the str string parameter being passed, which will contain only the characters "(" and ")", and determine the minimum number of brackets that need to be removed to create a string of correctly matched brackets. For example: if str is "(()))" then your program should return the number 1. The answer could potentially be 0, and there will always be at least one set of matching brackets in the string.*/
(function RemoveBrackets(str) {
let tempArr = []
for(let i = 0; i < str.length; i++){
if(tempArr[tempArr.length-1] === '(' && str[i] === ')'){
tempArr.pop()
}else{
tempArr.push(str[i])
}
@Smakar20
Smakar20 / KoUf-0.js
Created September 7, 2017 18:41
null created by smakar20 - https://repl.it/KoUf/0
/*Have the function LongestWord(sen) take the sen parameter being passed and return the largest word in the string. If there are two or more words that are the same length, return the first word from the string with that length. Ignore punctuation and assume sen will not be empty.*/
function LongestWord(sen) {
let arr = sen.replace(/[^\w\s]/gi, '').split(' ')
let longest = ''
let len = 0
for(let char of arr){
if(char == ' ') continue
if(char.length > len){
@Smakar20
Smakar20 / Kovh-0.js
Created September 7, 2017 22:56
null created by smakar20 - https://repl.it/Kovh/0
/*Have the function WildcardCharacters(str) read str which will contain two strings separated by a space. The first string will consist of the following sets of characters: +, *, and {N} which is optional. The plus (+) character represents a single alphabetic character, the asterisk (*) represents a sequence of the same character of length 3 unless it is followed by {N} which represents how many characters should appear in the sequence where N will be at least 1. Your goal is to determine if the second string exactly matches the pattern of the first string in the input.
For example: if str is "++*{5} gheeeee" then the second string in this case does match the pattern, so your program should return the string true. If the second string does not match the pattern your program should return the string false.*/
function WildcardCharacters(str) {
// code goes here
let strArr= str.split(' ')
let specChar = strArr[0]
let charStr = strArr[1].split('')
@Smakar20
Smakar20 / KtzF-0.js
Created September 10, 2017 18:12
null created by smakar20 - https://repl.it/KtzF/0
//determine if a string has all unique characters.
(function isUnique(str){
var charMap ={}
var ignoreCaseStr = str.toLowerCase()
for(var i=0; i< ignoreCaseStr.length;i++){
if(charMap[ignoreCaseStr[i]] == undefined){
charMap[ignoreCaseStr[i]] = ignoreCaseStr[i]
}
else{
return false
@Smakar20
Smakar20 / Kovh-1.js
Created September 11, 2017 18:39
null created by smakar20 - https://repl.it/Kovh/1
/* Have the function TimeConvert(num) take the num parameter being passed and return the number of hours and minutes
the parameter converts to (ie. if num = 63 then the output should be 1:3). Separate the number of hours and minutes
with a colon. */
(function timeConvert(num) {
// code goes here
if(num == 0) return "0:0"
if(num < 60) return "0:" + num.toString()
return Math.floor((num/60)).toString() + ":" + (num%60).toString()
@Smakar20
Smakar20 / Kovh-2.js
Created September 11, 2017 19:10
null created by smakar20 - https://repl.it/Kovh/2
/*Have the function simpleSymbols(str) take the str parameter being passed and determine if it is an acceptable sequence by either returning the string true or false. The str parameter will be composed of + and = symbols with several letters between them (ie. ++d+===+c++==a) and for the string to be true each letter must be surrounded by a + symbol. So the string to the left would be false. The string will not be empty and will have at least one letter.*/
(function simpleSymbols(str){
let regExp = /^[A-z]+$/
if(str.length == 1){
if(str.match(regExp)) return false
return true
}
if(str[0].match(regExp) || str[str.length-1].match(regExp)) return false
for(let i = 0; i < str.length; i++){
@Smakar20
Smakar20 / Kovh-3.js
Created September 11, 2017 21:54
null created by smakar20 - https://repl.it/Kovh/3
/*Have the function arithGeo(arr) take the array of numbers stored in arr and return the string "Arithmetic" if the sequence follows an arithmetic pattern or return "Geometric" if it follows a geometric pattern. If the sequence doesn't follow either pattern return -1. An arithmetic sequence is one where the difference between each of the numbers is consistent, where as in a geometric sequence, each term after the first is multiplied by some constant or common ratio. Arithmetic example: [2, 4, 6, 8] and Geometric example: [2, 6, 18, 54]. Negative numbers may be entered as parameters, 0 will not be entered, and no array will contain all the same elements. */
(function arithGeo(arr){
let diff = Math.abs(arr[1] - arr[0]),
geo = Math.abs(arr[1]/arr[0]),
lastDiff = 0
lastGeo = 0
for(let i = 2; i < arr.length; i++){
if(i == 2){
@Smakar20
Smakar20 / Kx1O-0.js
Created September 11, 2017 23:36
null created by smakar20 - https://repl.it/Kx1O/0
function ArrayAdditionI(arr) {
// code goes here
var sortedArr = arr.sort(function(a, b) {
return a - b}), sum = 0, numMap = {}
console.log("sortedArr: ", sortedArr)
for(var i = 0; i< sortedArr.length-1; i++){
sum += sortedArr[i]
numMap[sortedArr[i]] = sortedArr[i]
if(sum == sortedArr[sortedArr.length-1] || numMap[sum - sortedArr[sortedArr.length-1]] != undefined) return "true"
@Smakar20
Smakar20 / Kx1O-2.js
Created September 11, 2017 23:36
null created by smakar20 - https://repl.it/Kx1O/2
/*Have the function CamelCase(str) take the str parameter being passed and return it in proper camel case format where
the first letter of each word is capitalized (excluding the first letter). The string will only contain letters and some
combination of delimiter punctuation characters separating each word.
For example: if str is "BOB loves-coding" then your program should return the string bobLovesCoding. */
(function CamelCase(str) {
// code goes here
let arr = str.toLowerCase().split(/[,.~!@#$%^&*()\-_+' ']/)
let outputStr = ""