Skip to content

Instantly share code, notes, and snippets.

View Stefanacef's full-sized avatar

Stefana Stefanacef

View GitHub Profile
@Stefanacef
Stefanacef / Create Capitalize Letters.js
Last active September 25, 2021 09:01
Capitalize Letters | Solution | JavaScript
//Capitalize Letters
const word = "i love you";
const firstL = function (word) {
const w = word
.toLowerCase()
.split(" ")
.map((word) => {
// return word.slice(0,1).toUpperCase()+word.slice(1)
return word[0].toUpperCase() + word.substr(1);
@Stefanacef
Stefanacef / Factorialize a Number.js
Last active September 25, 2021 09:00
Factorialize a Number | Solution | JavaScript
//For example: 5! = 1 * 2 * 3 * 4 * 5 = 120
function factorialize(num) {
let numFac=[] ;
for(let i=1;i<=num;i++){
if(numFac.indexOf(num[i])==-1){
numFac.push(i);
}
@Stefanacef
Stefanacef / Find the Longest Word in a String.js
Last active September 25, 2021 08:58
Longest word |Solution | JavaScript
//Return the length of the longest word in the provided sentence.
function findLongestWordLength(str) {
const strSplit = str.split(" ").map((val, i, arr) => {
return val.split("").length;
});
const strL = Math.max(...strSplit);
@Stefanacef
Stefanacef / Get the difference (sum)diagonals in the matrix on javascript.js
Last active August 8, 2022 16:31
Diagonal Difference | Solution | JavaScript
let arr = [
[-1, 1, -7, -8],
[-10, -8, -5, -2],
[0, 9, 7, -1],
[4, 4, -2, 1],
];
function diagonalDifference(arr) {
// Extraction of the primary diagonal
let left = arr
.map((e, i) => {
@Stefanacef
Stefanacef / Integer Reversal.js
Created September 25, 2021 10:25
Integer Reversal Solution | JavaScript
//Integer Reversal
const number=123456;
const rev = function (num) {
const numRev = number
.toString()
.split("")
.reverse()
.join("");
return parseInt(numRev);
};
@Stefanacef
Stefanacef / largest number.js
Created September 25, 2021 10:28
largest number from each provided sub-array| Solution | JavaScript
//Return an array consisting of the largest number from each provided sub-array. For simplicity, the provided array will contain exactly 4 sub-arrays.
function largestOfFour(arr) {
subArr=[];
arr.map((val)=>{
return subArr.push(Math.max(...val))
})
return subArr;
}
@Stefanacef
Stefanacef / max and min summ.js
Created September 25, 2021 14:23
Find the minimum and maximum values that can be calculated by summing exactly four of the five integers | Solution | JavaScript
const arr = [7, 69, 2, 221, 8974];
function miniMaxSum(arr) {
let result=[]
arr = arr.sort((a, b) => {
return a - b;
});
result.push(arr.slice(0,4).reduce((acc,e)=>acc+e))
result.push(arr.reverse().slice(0,4).reduce((acc,e)=>acc+e))
console.log(...result)
@Stefanacef
Stefanacef / Count duplicate| Solution |JavaScript.js
Created September 27, 2021 10:53
Count the number of times a value appears in a JavaScript array
let arr = [3, 2, 1, 3];
function countDuplicate(arr) {
let number = 0;
arr.find((item, index) => {
if (arr.indexOf(item) !== index) {
number=item // find the duplicate (return 3)
}
});
// you can use just the function below if you know the exact value for the duplicate
function getOccurrence(array, value) {
@Stefanacef
Stefanacef / Number Line Jumps| solution | JavaScript.js
Created September 29, 2021 11:06
Solution for "Number Line Jumps" in Hackerrank
function kangaroo(x1, v1, x2, v2) {
if (x1 > x2) {
if (v1 >= v2) return "NO";
}
if (x2 > x1) {
if (v2 >= v1) return "NO";
}
let jump = (x2 - x1) / (v2 - v1);
@Stefanacef
Stefanacef / Basic Git commands
Last active October 5, 2021 08:43
Basic Git commands
First time:
git config --global user.name "Stefana" -it is important to use the same username as on github
git config --global user.email "stefana@...."
Every time:
git init -Create a new local repository
git add -A , Add one or more files to staging
git commit -m, -first compit
git status -List the files you've changed and those you still need to add or commit
git remote add origin <server(link from your repo)>