Giter Club home page Giter Club logo

healthit-practical-questions-test's Introduction

Question 3:


Using a framework of your choice, write a program that does basic CRUD operation using a DBMS of your choice while adhering to best coding practices

Solution

Reactjs Node Mysql CRUD

A simple CRUD made with Reactjs, Nodejs and Mysql

Home

home layout

Edit

edit layout

Tools

Install Run

To install and run the

  1. Frontend - Download the zip file, navigate to the client folder then run the commands below
    npm install
    npm run dev

  2. Backend - Download the zip file, navigate to the server folder then run the commands below
    npm install
    npm run dev

Question 4:

Part 1

Write a simple , well documented source code that reads from a text file, searches for a specific string and displays the number of occurrences of that string in the text file.

Solution

# searchString.js

This JavaScript file contains two main functions: readFile and countOccurrences.

readFile Function

The readFile function takes a file path as an argument and reads the file content synchronously using Node.js's fs.readFileSync method. The content of the file is returned as a string.

function readFile(filePath) {
    return fs.readFileSync(filePath, 'utf8');
}

countOccurrences Function

The countOccurrences function takes two arguments: a text to search in and a string to search for. It creates a global regular expression with the search string and uses the match method to find all occurrences of the search string in the text. The number of matches is returned.

function countOccurrences(text, searchString) {
    const regex = new RegExp(searchString, 'g');
    return (text.match(regex) || []).length;
}

Usage

The script reads a text file (sampleFile.txt) and counts the number of occurrences of the string 'amet' in the file content.

const text = readFile('Question 4/sampleFile.txt');
const occurrences = countOccurrences(text, 'amet');
console.log(occurrences);

The result is logged to the console.

Part 2

Write a function that reads any of the following file formats, removes special characters and converts the file to an sql file with headers

writeSql.js

This JavaScript file contains three main functions: removeSpecialCharacters, convertToSql, and writeSqlFile.

removeSpecialCharacters Function

The removeSpecialCharacters function takes a string as an argument and removes any special characters from it, leaving only alphanumeric characters and spaces.

function removeSpecialCharacters(str) {
    return str.replace(/[^a-zA-Z0-9 ]/g, "");
}

convertToSql Function

The convertToSql function takes an input file path and an output path as arguments. It determines the file extension of the input file and reads the file accordingly. If the file is a CSV file, it uses the csv-parser module to parse the file. If the file is an XLSX file, it uses the xlsx module. The function removes any special characters from the data and stores the cleaned data in an array.

function convertToSql(inputPath, outputPath) {
    // ...
}

writeSqlFile Function

The writeSqlFile function takes the cleaned data and an output path as arguments. It generates a string that represents the SQL commands to create a table and insert the data into the table. This string is then written to a new .sql file at the output path.

function writeSqlFile(data, outputPath) {
    // ...
}

Usage

The script can be used to convert a CSV or XLSX file to an SQL file with the data cleaned of special characters. The input file path and output path should be provided as arguments to the convertToSql function.

convertToSql('path/to/input.csv', 'path/to/output.sql');

The output will be an SQL file with commands to create a table and insert the cleaned data.

Question 5:

Using the language of your choice develop a solution that provided url can be able to shorten the url with a custom domain name

Solution

shortenUrl.js

This JavaScript file contains two main functions: shortenUrl and getOriginalUrl, and a urlDatabase object to store the original URLs.

shortenUrl Function

The shortenUrl function takes two arguments: the original URL and a custom domain. It generates a random 8-character hexadecimal string using Node.js's crypto.randomBytes method. This string is used as a short ID for the original URL, which is stored in the urlDatabase object. The function then returns the short URL, which is the custom domain followed by the short ID.

function shortenUrl(originalUrl, customDomain) {
    const shortId = crypto.randomBytes(4).toString('hex');
    urlDatabase[shortId] = originalUrl;
    return `${customDomain}/${shortId}`;
}

getOriginalUrl Function

The getOriginalUrl function takes a short ID as an argument and returns the original URL from the urlDatabase object.

function getOriginalUrl(shortId) {
    return urlDatabase[shortId];
}

Usage

The script first shortens a URL ('https://www.example.com') using a custom domain ('http://mydomain') and logs the short URL to the console. It then extracts the short ID from the short URL, retrieves the original URL using the short ID, and logs the original URL to the console.

const shortUrl = shortenUrl('https://www.example.com', 'http://mydomain');
console.log(shortUrl);

const shortId = shortUrl.split('/').pop();

const originalUrl = getOriginalUrl(shortId);
console.log(originalUrl);

The output should be the short URL followed by the original URL.

healthit-practical-questions-test's People

Contributors

mwovi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.