Skip to content

Commit

Permalink
Update js codes.docx
Browse files Browse the repository at this point in the history
  • Loading branch information
priya42bagde authored Oct 16, 2022
1 parent 4bcab83 commit 66d9104
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions js codes.docx
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,21 @@ function findTriplets(arr, n) {
}
var arr = [-1, -4, -9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
findTriplets(arr, 0);
------------------------------------------------------------------------
function findTriplets(arr, n) {
arr.sort((a, b) => a - b);
for (let i = 0; i < arr.length - 2; i++) {
for (let j = i + 1; j < arr.length - 1; j++) {
for (let k = j + 1; k < arr.length; k++) {
if (arr[i] + arr[j] + arr[k] === 0) {
console.log(`${arr[i]}, ${arr[j]}, ${arr[k]}`);
}
}
}
}
}
let arr = [1, 2, 5, 3, -2, 0, 1, -1, 5, 6, -2, -1];
findTriplets(arr, 0);
================================================================================================================================================================================
Convert Array into object:-
const arr = ["John", "Peter", "Sally", "Jane"];
Expand Down

0 comments on commit 66d9104

Please sign in to comment.