instruction
stringlengths
71
71.9k
Background Disclaimer: Skip if you are not interested in the background. The code is far far simpler than this. The problem is more about programming than math. Here is the definition of multiplication with broadcasting in human readable language. I am trying to optimize the multiplication of large n-dimensional a...
Another journey down the difficult path! I'd like to know if there's anything I haven't accounted for, if this can be significantly improved, etc. (Just as a side-note, I know that some of the formatting is a bit off; some places are spaced out a bit to make it more visually appealing.) using System; namespace Data { ...
This problem is taken from the book Introduction to Algorithms, Third Edition By Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein: In order to transform one source string of text x[1..m] to a target string y[1..n], we can perform various transformation operations. Our goal is, given x an...
I recently wrote a simple Brainfuck interpreter in Ruby: require "io/console" $VALID = "+-<>.," def parse(code, level=0) ast = [] while !code.empty? do c = code.shift if c == "]" then if level == 0 then throw Exception.new "Unmatched brackets" else ...
I made a simple insertion sort in F#, it uses a tail recursive shift function that attempts to shift an element in a list until it is in the right order. Would like some feedback on the design. let insertionSort xs = let shiftInsert xs x = let rec shift xs x f = match xs with | [] ->...
In my previous post I was looking for a better solution to write a single column of a 2D array into a worksheet besides looping between code and worksheet and finally managed to achieve that. On deploying my code, I found that the double loop to compare two arrays was inefficient when it came to comparing arrays of 5,0...
I'm testing my game using Firefox, and it's slow whenever it's in fullscreen. If I resize the browser to take up half the screen, it'll scale the image down and run fine. Game also runs fine in Chrome in full screen. I'm using a laptop with an i7 4000HD series CPU.. The window size shouldn't make a difference, as I hav...
Looking for a general review: #ifndef HASH_TABLE_HASH_TABLE_H #define HASH_TABLE_HASH_TABLE_H #include <utility> #include <stdexcept> namespace mds { template<typename K, typename V > class hash_table { std::size_t M; std::pair<K, V> *table; bool *mark; std::siz...
How can I improve this code? It computes the Ackermann function as long as m<4 and n<13. #include <iostream> #include <limits> // Ackermann function calculations unsigned int ackermann(unsigned int m, unsigned int n){ if(m == 0) return n+1; if(n == 0) return ackermann(m-1,1); return ackerma...
I have two implementation which I modified according to my need to create a triangle or a pyramid like this: * *** ***** ******* ********* First way: int num = 5; for(int i=0;i<num;i++) { for(int j=0;j<num-i;j++) { System.out.print(" "); } for(int k=0;k<=i;k++) { System.out...
This is a follow up to my last question: Partition a singly linked list using Java Based on the feedback I received there, I changed the following about the code: Added a LinkedList class. Removed some variables from the partition method. Changed the partition algorithm so that the output of the lower and upper partit...
A few days ago I asked this question. So far I have made many changes in the code, as well as added some on and I was wondering if you see any way the code could be obviously optimized, as well as any suggestions you may have. Note: I was thinking for the vampire race I would create a const variable called vampireFood...
The parameters list contain the array that is passed to and the size of the array respectively. Is there anywhere I could improve my code? void bubbleSort(int a[], int s) { for (int i = 1; i < s; i++) { for (int j = 0; j < s - i; j++) { if (a[j] > a[j + 1]) { int temp = a[j]; ...
I am trying to implement search in Laravel. I want to search on models. Since there can be many records in the database, I am trying the chunk function. public function searchLeads($param) { $results = array(); // get all leads Lead::chunk(100, function($leads) use ($results, $param) { ...
The parameters list contain the array that is passed to and the size of the array respectively. Is there anywhere I could improve my code? void insertionSort(int a[], int s) { for (int i = 0; i < s - 1; i++) { int j = i + 1; int key = a[j]; while (i >= 0 && a[i] > key) { a[i+1] =...
This is the complete rewrite of a function to decode an UTF-8 codepoints and return the encoding length (or 0 if the codepoint is \0). In response to the review of my previous version I decided that I needed a different approach and I should recognize ALL the invalid encodings (as per reviewer suggestion). If an invali...
In one site there was one practice question which ask you to make one program: Tapas and Meghana are appointed as the one responsible for interviews of AXIS Core committee '17 ! In order to decide upon the order in which to call the aspirants for the interview, they have come up with a brilliant game. It goes li...
Is there anything to make the cosine similarity function more optimized in terms of CPU execution time? double cosine_similarity(double *A, double *B, unsigned int size) { double mul = 0.0, d_a = 0.0, d_b = 0.0 ; for(unsigned int i = 0; i < size; ++i) { mul += A[i] * B[i] ; d_a += A[i] * A...
First of all I know my code is highly vulnerable to SQL injections, but I wanted to code the base first. I have a feeling this can be done with fewer lines and less repeating. I'm sorry if it is really bad code I just started learning C#. public DataTable GetData(string search, int filter) { switch ...
Accomplishment: Tic Tac Toe game with Python & Kivy I have created a simple tic tac toe game with a random bot logic (really random after a user selects a mark). Next step would be to insert the minimax algorithm for example, but I would like to know if the path I've taken to construct my code is correct and could it b...
This is a simple library I just finished writing. The main function is entropy(), which returns the entropy of a file. I'd really appreciate suggestions to improve it. caos.c: #include <stdio.h> #include <math.h> #include <unistd.h> #include <sys/stat.h> #include "caos.h" static unsigned long long int wc(const char * ...
I'm trying to make a random object spawning script in Unity. Bellow is the code, any suggestions for improvement / changes? I'm new to both Unity and C#. // Game objects and Transforms public Transform playerTransform; public Transform[] obstaclePrefab; // spawn params public float minYDicstane = 6.0f; public float ma...
It occurred to me that if SHA2 can be used to derive keys from passwords, then it might as well be good enough to generate random data that can be xored with a plaintext to encrypt and the other way around. These are my assumptions: SHA-512 produces a random-looking output that is impossible to guess The result of SHA...
So I was thinking of making a C# REPL, as I didn't find any viable solution that would work for me, so I made a simple, basic one, I am sure it can be improved, as it seems once the REPL class is initialized it's hard to add an event handler to it, or access the logs, so I am looking for a way to improve it, here's the...
I'm learning Clojure and solved Project Euler #1, I'd like to have my code reviewed on all aspects and have one specific question. This is also my first Functional Programming language, I have however used some form of FP in Java and Python before. Task: Multiples of 3 and 5 If we list all the natural numbers below 10...
I am getting some customer data but don't know the complete schema beforehand. I want to parse this data and create a Scala object from it. But due to unknown fields in the record, I fill only the important fields and remaining record data is dumped in a remData placeholder field. This remData is used so that we can st...
I am studying computer science and recently I developed an application in Java (it is a minecraft mod) that connects a MySQL database and queries to fetch, update or insert data. My DatabaseHandler class is the one that initialize the connection to the database and performs all the necessary queries my application need...
Today I spent quite some time on providing a solution for a Stack Overflow answer. It looked quite easy to me, but my solution is complex. The question can be found here and this is my answer. If I understood the question correctly it came down to obtaining all values for keyWeWants from a data structure like this: { ...
I have written some code (below) which iterates over each character of a string and adds that character to every index of previous permutations. For example, in case of abc: b is added to every index of perm(a) resulting in ab, ba. Now c is added to every index of perm(c) resulting in cab, abc, acb, cba, bac, bca. I us...
I have an example array like: array = [1, 2, 3, 4, 5, 6] Every of this numbers refers to an object that has text property. I want to make sure that every of these object has the same text value. Currently I do it like this: correct = [] for number in array: if(object[number].text == "Sample"): correct.append(num...
I'm learning Clojure and solved Project Euler #1, I'd like to have my code reviewed on all aspects. I'm marking this as follow-up of Project Euler #1 because I answered my own question and implemented it. Task: Multiples of 3 and 5 If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, ...
Below is the current working code for an ongoing project. I am wondering if there is anything I can do to improve the code snippet below. My main concerns lie to two area. First being that I append the answer of an input to a list called inputList and then call it in a block of conditionals. I am wondering if this in p...
I've got several UIViewControllers that are trying to do too much so I'm trying to learn how to clean them up so that they only have code that does UI things (ultimately getting things to conform to MVVM). I know my code needs a lot of improvement so I'm going to start small by focusing on one particular behavior to a...
Feel free to critique my code and offer suggestions on how to clean it up and make it more presentable. I have been working on this for a few days, and learning as I go. from __future__ import print_function import random import sys #Global variables dealerWins = 0 playerWins = 0 dealerCard = [1,2,3,4,5] playersCard...
This problem should self explanatory based on namings of variables and functions. In essence I am doing well over 720*720*90 checks/calculations. Hence, this is taking far, far too long. How do I make my code more optimized with regards to time/performance. Space is not an issue. The question is pretty complicated(at l...
I've implemented my own 'power-mod' procedure which will compute a^b 'mod' n for some large b and even larger n. I think the way I've done it is a common procedure, and it does seem well optimised, but I really need to squeeze the maximum performance out of it as it is currently the bottleneck in my program (~75% of th...
The next assignment in my class is to create a program that allows the user to input an inventory, and then display the total value of the inventory. We are required to create a class with both private and public member functions. I tried to keep it as streamlined as possible but I know there is always room for impro...
Newbie here, presenting the code for close public scrutiny. Couple remarks regarding the context (taken from Princeton's COS 226 course): In this problem I model a percolation system using an N-by-N grid of sites. Each site could be either open or blocked (all of them are blocked initially). To open the site, client ...
I have a ScrollPane which allows for wrapping around the screen through some nice code. However, in order to achieve this I have had to use 5 ImageViews with each of them being the size of the screen. This causes the computer to run very slowly when panning around and loading. Is there a way to distribute the weight on...
Exercise assignment: Build a calculator with React which can add, subtract, multiply and divide. See image below for reference Give it whatever design and colors you want Each text field should have a placeholder The result field should be able to be copied but not edited Make sure your math is correct and calcu...
I recently created Copy, an esoteric language, and wrote an implementation in Ruby. The language has only 7 instructions: copy <a> <b> <c> Copy the code block from a to b at c remove <a> <b> Remove the code block from a to b skip <value> Skip the next instruction if value is not 0 add <var> <value> Add value to var ne...
I have solved the classic "Merchants Guide to Galaxy" problem: A merchant buys and sells items in the galaxy. Buying and selling over the galaxy requires you to convert numbers and units. The numbers used for intergalactic transactions follows similar convention to the roman numerals. Roman numerals are base...
I’m wondering is the following function returns a list of three numbers sorted in ascending order with the minimum possible number of operations, or if there is some more efficient or elegant method (a part from using the primitive function sort!) (defun order (min mid max) "sort three numbers in ascending order" (wh...
Problem statement: Given a sorted (increasing order) array with unique integer elements, write an algorithm to create a binary search tree with minimal height. Assumptions: The array (and therefore BST) will only contain the type int. Other integral types are unsupported. The problem statement's description is a prec...
I designed and implemented a custom language. After @LeakyNun refactored it to improve speed, it looks like this. I personally like it right now, but is there any more hyperoptimizations for both readability and performance? /* *Feel free to modify and distribute the code and all relevant documentation * This code is ...
I'd like to verify that the security of this JavaScript code is correctly doing what I believe it's doing. Its intended purpose is to generate xkcd-style passwords randomly in the visitor's browser. When the page loads, the full wordlist is loaded into the browser synchronously (>350K words) and then generates a secur...
I'm a student and this is one of my assignments. My professor basically confirmed that my code is correct but all he grades on is if I finished the assignment correctly but not the coding style. I think I did poorly in terms of code style and implementation. I'm very frustrated and would like some guidance on how to im...
I'm looking for feedback on my URLEncoder implementation, which is a drop-in replacement for Apache Tomcat's URLEncoder. It was completely ignored by the project committers (and I got no feedback why) and I'm curious if it's just that bad, or I failed to communicate why it's better than the original one. /* * Licensed...
This is a single isomorphic class in ES6, written with the intention of generating a full WAV file given note names and durations in seconds. In JavaScript it can be exported as a Blob and in Node.js it can be exported as a Buffer, to be written to the filesystem. I have left thorough comments in the code to help docum...
I haven't yet implemented any sort of graph thus far in C and decided to give it a go by trying to implement an adjacency list in C. Is there anything in my code that you see that I can improve and is there any other sort of basic functionality that is missing in my adjacency list and should be added? Graph.h #ifndef G...
The tests are taken from this answer on an insertion sort in rust question. The algorithm is taken from Algorithms in a Nutshell (2nd Edition). I'm not looking at crazy performance, the goal being to learn about basic algorithms and rust, but if there is something shockingly inefficient please let me know. fn main() {}...
This is one of my first programs working with APIs and I was hoping to get some input in the form of suggestions, recommendations or corrections. The goal is to register the user location by IP, derive a latitude and longitude from the ip-api public site, pass this to Open Weather’s API for weather details and descrip...
This is the first program I've ever made in Python, and I never really studied the language (just looked at bits of code online) so I'm sure the performance is less than optimal. The Objective: At my college, security alerts are occasionally sent to our phones, and sometimes posted to our subreddit for discussion. To a...
In C++, primitive types are treated differently than user-defined types. If you do not initialize them, their values are undefined in some cases. This is an easy mistake to make. I wanted to make a class that wraps primitive types, etc. so that the default constructor is always called without adding any other run-time ...
If you're familiar with std::tuple, you're aware that accessing its elements is slightly unusual. Instead of using a member function, we're provided with the function std::get instead. I was curious as to why this is, so I conducted a brief search. The few websites that I saw all gave the same reason: the code used to ...
Here is a short program web scraping program written in Node.js. I'm just getting to grips with node and this is the first thing I've written with it. I'm liking it so far though I guess I'm kinda missing the point with the whole asynchronous aspect. This is supposed to be an extremely basic project. I'm just a beginne...
My problem is that you have a lot of ifconditions to be checked and inside that if condition you have multiple lines of code. I want to eliminate it and use inheritance instead. For every if statement I will be using a separate class to handle it. This is more like a derivative of the command pattern but not command pa...
I have the actions and the times in an instructions.js file: module.exports = { temperature : { "00:00" : 100, "01:00" : 110, "02:00" : 120, "03:00" : 130 }, ventilation : { "00:00" : 0, "00:30" : 25, "01:30" : 75, "02:30" : 100 }, end : "03:30" } Then after importing the inst...
I'm parsing an XML file and searching for a child value. As I'm familiar with this XML file structure, I know that the final value is a child of a child, and so I wrote the following code section: /*Parse XML file and find device friendlyName*/ pxUpnp = ezxml_parse_file(XML_FILE_PATH); pxUpnpChild = ezxml_child(pxUpnp...
I wrote the following lines of code to compare some strings with contents of columns (string) in SQLite database: void PaymentTransaction::setAttributesBySqliteStmt(sqlite3_stmt * statement) { ZF_LOGD("setAttributesBySqliteStmt\n"); int columnCnt = sqlite3_column_count(statement); for (int i = 0; i < column...
package com.unisa.pf.sp52016.assign01; import com.unisa.pf.sp52016.assign01.Predator.STATUS; /** * <strong>Overview</strong><p> * This code comprises a component of a larger game. You have been asked to implement the structure * that maintains a group of Predators that could be a Pack of friendlies or enemies. ...
I want to calculate how similar two objects are according to a database. However the code is very slow; it takes around 2 minutes to analyze just 3 objects. How can I speed it up? I have tried to avoid for loops, and I'm also avoiding recalculating things. This functions returns the ith comparison of the n elements in...
(Homework alert) Working my way through "The Haskell Road...", not sure about my solution to exercise 2.15 on page 48 of the second edition: A propositional contradiction is a formula that yields false for every combination of truth values for its propositional letters. Write Haskell definitions of contradiction tests...
I'm developing a mobile app with Cordova, jQuery and jQuery mobile. To synchronise the data saved on a device I make AJAX calls to a server (I'm sending and requesting data). The data is saved in a database on the device with this SQLite plugin for cordova. The server-side connection is handled by a php file. Everytime...
The puzzle goes like this: in a rectangular 2D grid there are empty spaces (.), exactly one starting point (S, s) and obstacles (denoted below by X's). The objective of the puzzle is to find a path starting at the starting point and going through each empty space exactly once (a Hamiltonian path). You can't, of course ...
I solved the Nested List Python challenge on HackerRank.com passing all test cases. Although this problem can likely be solved with a short script with clever one-liners, my approach was instead to solve it in a clean, understandable way in functional style. Here is a summary of the challenge, see link above for full d...
I'm working on an important project. We're an IT services provider and we have a project where we have to build a new system to process data from a specific client. The problem is that usually we process their data, but they send us a pre-processed data that's easy to parse, but this time around, they're trying with a ...
I'd like to have the code below reviewed on all aspects. Task: Largest prime factor The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? My solution shared.clj (ns shared) (defn prime-seq [] ((fn prime-seq-gen [s] (cons (first s) (lazy-seq (pri...
I've done a random quote machine in jQuery. Could you look at the code and propose some improvements (especially jQuery code)? Here's the working app. var quotes = [ { "quote": "Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.", "author": "Albert E...
I have written an efficient way to control data to be cached/not-cached in HttpCache using JSON and C# controlling it. The reason for this implementation is to make use of existing application servers to store cache to save network latency and call across processes. another reason was to minimize code change after we f...
I am reviewing the following code written by a fellow developer. I am not an java expert but IMHO i did not feel this is efficient use of exceptions — the reason I feel so is: The below code throwing exception — seems like flow control. Since we are just using it add a attribute error attribute to PageErrorRequestAttr...
I am writing a PHP service which will listen for JSON requests (made using jQuery) and will return the JSON responses. The whole template for such services (there will be 5) I have shortened into this template: <?php // set the headers which are accepted header("Access-Control-Allow-Origin: *"); header("Access-Control...
I wanted to get your opinion on this immutable implementation of a Phone Book using recursion to process a stream. I am especially interested in ways to speed up the code execution. Here is an example of expected input: 8 add 811 Mom1 add 12376213 Mom2 add 1732239 Bob find 76213 find 910 find 811 del 811 find 811 Now,...
I have a test where I have to validate the order of items in a List based on a pre-defined hierarchy that is being given to me as part of my assignment. Here it is below. Cat Dog Horse Elephant The items in the list would only ever be those four types, but the size of list is not limited. The list will be passed...
Some days ago, I figured out that I'd like to get a notification every time a new question is asked here. So, I've made a really simple Python script, which uses pync (only OSX compatible) to do that for me. I'd like to get some feedback regarding anything that comes to your mind, including good practices. That's not a...
As an assignment for a class, I have made a small Harry Potter family tree in Prolog. It compiles into a self-contained executable that can be run straight from the command line on Linux machines. This is my second ever program in Prolog, so I am still learning. My background is in imperative languages, so I am probabl...
I have this recursive function that I made which prints a table, but I really think my current solution is really ugly. Does anyone have an idea as to how I can improve my solution? I'm trying to implement without any variables and with the use of sprintf. let rec rec n = if n > 0 then rec(n-1) + sprintf "\n"+...
I've been toying around with writing a decentralized, P2P application in REBOL 2, and one of the things I need to do is generate a universally unique identifier for users. I have written a function that generates a Version 4 UUID that is compliant with RFC 4122, as best as I can tell. I have a few questions ... Is it ...
I was doing a simple problem on codingbat and testing out my python. The problem was: Given two int values, return their sum. Unless the two values are the same, then return double their sum. sum_double(1, 2) → 3 sum_double(3, 2) → 5 sum_double(2, 2) → 8 My solution was: def sum_double(a, b): if a is b: return...
I wrote this little Bash function to replace my sudo command. It checks whether I have an alias for the given command and runs the aliased command instead of the literal one in that case. As this is going to be used with sudo, I want to be sure there are no critical mistakes in it which generate security or safety issu...
I am starting to write a CLI using argparse library. This is my first attempt to structure a large project, usually I write single script. The CLI auto is defined in a top directory, helper functions are in a subfolder named project and a main function (where I want to put the logic of my program) in sub-sub-folder nam...
I'm returning an array containing dates (and other things) from an API, then looping through the array on the front end to convert them into dates The backend uses Node.Js and queries a mySql database with the mySql module: pool.getConnection(function(err, conn) { conn.query('SELECT * FROM myData’, function(err, resu...
I am trying to create an area graph from the upper and lower limit values. First I created two line graph from those points as: Sample data points are: var line1dataPoints:[CGPoint] = [CGPoint(x: 10, y: 120),CGPoint(x: 20, y: 130),CGPoint(x: 20, y: 120),CGPoint(x: 70, y: 130),CGPoint(x: 70, y: 120),CGPoint(x: 80, y: ...
I am actually more confused rather than understanding the concept. I have been developing a system and want to know the MVC design pattern. which one is best and the concept and usability of the layers? In general, I have two approaches: 1. ViewModel layer (contains viewmodels), Models (contains models and datacontext)...
I am implementing myself a BigInteger class. It can natively handle very very big digits in very short time. 2 ^ 200000 == Time Elapsed : 12.343 Number of binary digits : 200001 The only problem is, when I do std::cout << foo;, I have to wait for very very long. Because my BigInteger class has to perform a std::string...
I have created a method which shows log in logcat and also writes into the file. Every time this method is called it appends String in file. There are so many read/write operations on disk/non-volatile storage/SD card happening. I want to batch these operations so that minimum SD card read/write happens and i do not mi...
I have a PHP bot running on a shared host. My account often get suspended. When I asked to web hosting service, they said that my account suspended because of excessive MySQL usage. There is an upload.php and db_functions.php files. Upload PHP runs every half hour. I open and close MySQL connections in every function. ...
I need two icons: If the email is verified, show an icon without a hyperlink and set an "activated" CSS class for green style and checked. If the email is not verified, the icon is linked to the verify page, and the default is a gray color style. Which of these solutions is better and standard? Solution #1: <a href="...
Since I'm new to coding, can you give me some advise on game class interactions? The game does work, but my code looks ugly and I think it can be improved a lot. What I'm mostly interested in: class1.setvalue(class2.returnvalue()) is this how it is supposed to be done? Should I derive my objects from some virtual ba...
I recently struggled with implementing AI in Tic Tac Toe game. For better understanding of minimax algorithm I've decided to separate AI's logic. When I finished I thought that some may find it useful, so I packed AI in easy-to-use API and described its usage in README file on GitHub. I am wondering if my code uses an...
I have a switch statement that references different configurations based on data pulled from a database. Each iteration of configuration has variations in what needs to be enabled/modified. I've set up a method that takes the varying arguments for each configuration and does relevant logic, generally changing elements ...
I'm trying to design a mapper that will convert one object type to another shown in the diagram below: The object has structure as follows (it's not a JSON): { "type": "DownloadAppComponent", "name": "Download App", "contentId": "download-app", "properties": { "iosUrl": "http://apple.com", "androidUrl": "http:...
For practice I wrote a function to generate a list of numbers from a start to an end by a step. I couldn't make it- like the built-in range- default start to 0, because all optional parameters must come after required ones, so def range(start=0, end, step=1) won't work. Here's my script: def Range(start, end, step=1): ...
I am using Vba excel to populate a list of all my .wtv files using the .GetDetailsOf method. There are some 3000 files across 4 hard drives filed in a b c... subdirectories. This sends my memory usage from just over 4 (normal) to nearly the full 8 GB available and halts my computer for a short time. Is there a better m...
I wrote a Snake Game in C++ and I have practiced some OOP approaches. I would really appreciate criticism and some advice. snakeGame.h #ifndef _SNAKEGAME_H #define _SNAKEGAME_H #include<SFML/Graphics.hpp> #include<map> #include<memory> #define maxSnakeLenght 100 class SnakeGame{ public: SnakeGame(int size...
I want to optimize code in my simple app that I'm writing to learn C#. I feel it's really badly optimized in terms of good coding practises. Could anyone take a look at it and give me a hint to make it look better? public void mainMenu(BookList b) { bool repeat = false; Console.WriteLine...
This is for machine learning. I have 5 matlab files: AWA, REM, S1, S2, SWS. Each one has 2 arrays: x and y. y are the labels. I want to know the number of instances for each category in each file: I load the matlab file I convert from f8 to int32 If I do not use ravel, bincount will not work I count the instances ...
My code is a variant on the Visitor Pattern and a "leaky bucket" variant. The goal is pretty straightforward: the "bucket" will collect a specified number of items (say, for example, 500) and then empty the queue, running some CPU-bound operation on ("visiting") each item. (Yes, I'm aware that there's probably existing...
Even though singletons are bad practice and often unnecessary, I still see many developers using this pattern over and over. Since implementation of this pattern usually requires some common code, I thought we could just make a base class to be extended. I came up with this so far. <?php namespace wl; /** * @dosc al...
I am new to JavaScript and wondered if there is a more streamlined way of writing this code: var choices = "ABBCD" // A string containing the letters A-D var total = 0 function calculate() { // Iterate through choices and add to total depending on the letter for (var i=0; i<choices.length; i++) { if (choices[i]=...