Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Second mini challenge #187

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
7 changes: 7 additions & 0 deletions Desktop.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"folders": [
{
"path": ".."
}
]
}
48 changes: 24 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
"volta": {
"node": "16.14.2"
}

}
Binary file added src/.DS_Store
Binary file not shown.
52 changes: 51 additions & 1 deletion src/isolate-duplicates/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,53 @@
function isolateDuplicates(text) {}
function isolateDuplicates(text) {
let general= []
let arr = []
let acc = []
let count = 0
let op = []
let cl = []
let lower;
if(typeof text === "string"){lower = text.toLowerCase()}
else{ throw Error("Please enter a valid string")}
for(let i=0;i<text.length;i++){
if(!acc.includes(lower[i])){
acc = []
acc.push(lower[i])
general.push(text[i])
}
else if(acc.includes(lower[i])){
acc.push(lower[i])
if(acc.length <= 2){
general.push(text[i])
}
else if(acc.length == 3){
if(lower[i] != lower[i+1]){
general.push('[')
op++
general.push(text[i])
general.push(']')
cl++
count++
}else if(lower[i] == lower[i+1]){
general.push('[')
general.push(text[i])
op++
count++
}
}
else if(acc.length > 3){
if(lower[i] == lower[i+1]){
general.push(text[i])
}else if(lower[i] != lower[i+1]){
general.push(text[i])
general.push(']')
cl++
}
}
} }
if(op.length>cl.length){general.push(']')}
arr.push(general.join(''))
arr.push(count)
return arr
}

module.exports = isolateDuplicates;
2 changes: 1 addition & 1 deletion src/isolate-duplicates/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ describe("Find Duplicates", () => {
7,
]);
});
});
});
43 changes: 42 additions & 1 deletion src/morse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,47 @@ const MORSE_CODE = {

Object.freeze(MORSE_CODE);

function morse(text) {}
function morse(text) {
let arr;
if(typeof text == "string" && typeof text != 'object'){
arr = text.split(' ')
let result = []
let gap = 0
for (let i=0;i<arr.length;i++){
let letter = MORSE_CODE[arr[i]]
arr[i] == '' ? gap++ : gap = 0;
if(arr[i] =='' && arr[i-1] == '' & gap ==2){
result.push(' ')
}else{
result.push(letter)
}

}
return result.join('').trim()
}else if(text === ""){
return "";
}else {
throw Error("Please provide a morse string");
}
// let arr;
// if(typeof text == "string"){
// arr = text.split(' ')
// let result = []
// let gap = 0
// for (let i=0;i<arr.length;i++){
// let letter = MORSE_CODE[arr[i]]
// arr[i] == '' ? gap++ : gap = 0;
// if(arr[i] =='' && arr[i-1] == '' & gap ==2){
// result.push(' ')
// }else{
// result.push(letter)
// }

// }
// return result.join('').trim()
// }else if(typeof text == 'undefined'){return}
// else{return "Please provide a morse string"}

}

module.exports = morse;
18 changes: 17 additions & 1 deletion src/remove-dulplicates/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
function removeDuplicates(obj) {}
function removeDuplicates(obj) {
let comp = []
let newObj = {}
let k = Object.keys(obj)
for (let i=k.length-1;i>=0;i--){
let value = obj[k[i]]
let newVal = []
for(let j=0;j<value.length;j++){
if(!comp.includes(value[j])){
comp.push(value[j])
newVal.push(value[j])
}
}
newObj[k[i]] = newVal
}
return newObj
}

module.exports = removeDuplicates;