Skip to content

Instantly share code, notes, and snippets.

View jvvppereira's full-sized avatar
💻

João Vítor jvvppereira

💻
  • Blumenau, SC, Brasil
View GitHub Profile
@jvvppereira
jvvppereira / toDecimal.js
Created October 2, 2025 11:23
binary to decimal
function toDecimal(binary) {
let decimal = 0;
const lastIndex = binary.length;
for (let index = 0; index < lastIndex; index++) {
const binaryChar = binary[index];
const decimalChar = binaryChar * (2 ** (lastIndex - 1 - index));
decimal += decimalChar;
}
@jvvppereira
jvvppereira / toBinary.js
Created October 2, 2025 10:59
decimal to binary
function toBinary(decimal) {
let binary = "";
let rest = decimal;
while (rest > 0) {
const remainder = String(rest % 2);
rest = Math.floor(rest / 2);
binary = remainder + binary;
}
@jvvppereira
jvvppereira / decode.js
Created September 14, 2025 22:33
Decode strings with parenthesis and needing reverting its order
function decode(s) {
let newStr = s;
const reverse = str => str.split("").reverse().join("");
const getInsideStr = word => {
const arr = [];
let str = "";
for (let index = 0; index < word.length; index++) {
@jvvppereira
jvvppereira / bubbleSort.js
Created May 17, 2024 13:02
bubbleSort manually
function bubbleSort(array) {
// Only change code below this line
let newArray = [];
let smallest = array[0];
let biggest = array[0];
newArray.push(smallest);
for (let i = 1; i < array.length; i++) {
const currItem = array[i];
@jvvppereira
jvvppereira / symmetric-difference.js
Created November 9, 2023 14:39
Symmetric difference
function sym(...args) {
let diff = [];
const checkArrays = (firstArray, secondArray) => {
const currentDiff = [];
for (let i = 0; i < firstArray.length; i++) {
const currValFstArr = firstArray[i];
if (!secondArray.includes(currValFstArr)) {
currentDiff.push(currValFstArr);
function telephoneCheck(str) {
const regex = /^(1)?\s?((\(\d{3}\))|(\d{3}))\s?-?(\d{3})\s?-?(\d{4})$/g
return regex.test(str);
}
const currency = [
{
name: "PENNY",
value: 0.01,
next: 0.05
},
{
name: "NICKEL",
value: 0.05,
next: 0.1
function rot13(str) {
const placesToRight = 13;
const letterA = 65;
const letterZ = 90;
const newStr = [];
for (let i=0; i<str.length; i++) {
const charCode = str.charCodeAt(i);
let newCharCode = charCode + placesToRight;
const isPrime = number => {
let isPrime = true;
for (let i = 2; i < number; i++) {
if (number % i == 0) {
isPrime = false;
break;
}
}
return isPrime;
function fibonacci(num) {
let total = 1;
let oldValue = 1;
let arr = [];
for (let i = 0; i < num; i++) {
arr.push(total);
if (i > 0) {
oldValue = arr[i-1];
}